青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Google code jam Round1B

Posted on 2010-05-25 23:29 rikisand 閱讀(389) 評論(0)  編輯 收藏 引用

A 簡單的模擬 ,不過我寫的很麻煩

Problem

On Unix computers, data is stored in directories. There is one root directory, and this might have several directories contained inside of it, each with different names. These directories might have even more directories contained inside of them, and so on.

A directory is uniquely identified by its name and its parent directory (the directory it is directly contained in). This is usually encoded in a path, which consists of several parts each preceded by a forward slash ('/'). The final part is the name of the directory, and everything else gives the path of its parent directory. For example, consider the path:

/home/gcj/finals
This refers to the directory with name "finals" in the directory described by "/home/gcj", which in turn refers to the directory with name "gcj" in the directory described by the path "/home". In this path, there is only one part, which means it refers to the directory with the name "home" in the root directory.

To create a directory, you can use the mkdir command. You specify a path, and thenmkdir will create the directory described by that path, but only if the parent directory already exists. For example, if you wanted to create the "/home/gcj/finals" and "/home/gcj/quals" directories from scratch, you would need four commands:

mkdir /home
mkdir /home/gcj
mkdir /home/gcj/finals
mkdir /home/gcj/quals

Given the full set of directories already existing on your computer, and a set of new directories you want to create if they do not already exist, how many mkdir commands do you need to use?

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each case begins with a line containing two integers N and M, separated by a space.

The next N lines each give the path of one directory that already exists on your computer. This list will include every directory already on your computer other than the root directory. (The root directory is on every computer, so there is no need to list it explicitly.)

The next M lines each give the path of one directory that you want to create.

Each of the paths in the input is formatted as in the problem statement above. Specifically, a path consists of one or more lower-case alpha-numeric strings (i.e., strings containing only the symbols 'a'-'z' and '0'-'9'), each preceded by a single forward slash. These alpha-numeric strings are never empty.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of mkdir you need.

Limits

1 ≤ T ≤ 100.
No path will have more than 100 characters in it.
No path will appear twice in the list of directories already on your computer, or in the list of directories you wish to create. A path may appear once in both lists however. (See example case #2 below).
If a directory is listed as being on your computer, then its parent directory will also be listed, unless the parent is the root directory.
The input file will be no longer than 100,000 bytes in total.

Small dataset

0 ≤ N ≤ 10.
1 ≤ M ≤ 10.

Large dataset

0 ≤ N ≤ 100.
1 ≤ M ≤ 100.

Sample

Input
Output

3
0 2
/home/gcj/finals
/home/gcj/quals
2 1
/chicken
/chicken/egg
/chicken
1 3
/a
/a/b
/a/c
/b/b

Gluk的解法:

 set <string> S;
        REP (i, n)
        {
            string s;
            cin >> s;
            S.insert(s);//已有的路徑用set表示
        }

        int res =0 ;

        REP (i, m)
        {
            string s;
            cin >> s;
            vector <string> ss;
            REP (j, s.size())
                if(s[j] == '/')
                    s[j] = ' ';//用空格替換’/’,然后使用istringstream分隔各級目錄
            istringstream iss (s);
            while (iss >> s) {
                ss.pb (s);
            }

            s = "";
            REP (i, ss.size ())
            {
                s = s+"/"+ss[i];
                if (S.find(s) == S.end())//依次加入各級目錄,/a  /a/b  /a/b/c 增加遞增的所有目錄
                {
                    res ++;
                    S.insert(s);
                }
            }
        }
題目中的這一句
If a directory is listed as being on your computer, then its parent directory will also be listed, unless the parent is the root directory.
告訴我們如果/a/b被list存在,那么/a也一定被list出來了 ,所以上面代碼可以不去分隔處理已經給出的目錄
yuhch123的解法
struct node {
   map <string, node *> sons;//每個節點,用map實現兒子節點
};
node *root;//一個根節點
int T;
int N, M;
char tmp[100005];
int ans = 0;
void insert(node *cnt, char *tmp) {//在節點cnt處,插入tmp子樹
   int i;
   if (tmp[0] == 0)//為空則返回
      return;
   assert(tmp[0] == '/');
   string str;
   for (i = 1; tmp[i] != '/' && tmp[i] != 0; i ++)//第一層
      str += tmp[i];
   if (cnt -> sons.find(str) == cnt -> sons.end()) {//如果沒有這子樹,則創建子樹
      ans ++;//需要一次mkdir 
      struct node *tmp2 = new node();
      cnt -> sons[str] = tmp2;
   }
   insert(cnt -> sons[str], tmp + i);// 遞歸創建子樹
}
int main() {
   int i;
   int Case = 1;
   scanf("%d", &T);
   while (T --) {
      scanf("%d%d", &N, &M);
      root = new node();
      for (i = 0; i < N; i ++) {
     scanf("%s", tmp);
     insert(root, tmp);
      }
      ans = 0;
      for (i = 0; i < M; i ++) {
     scanf("%s", tmp);
     insert(root, tmp);
      }
      printf("Case #%d: %d\n", Case ++, ans);
   }
   return 0;
}
neal.wu的解法
vector <string> parse (string s)
{
    vector <string> v;
    string next = "";
    
    for (int i = 0; i < (int) s.length (); i++)
    {
        next += s [i];
        
        if (i + 1 == (int) s.length () || s [i + 1] == '/')
        {
            v.push_back (next);
            next = "";
        }
    }
    
    return v;
}

set <string> direc;

int insert (vector <string> v)
{
    int count = 0;
    string s = "";
    
    for (int i = 0; i < (int) v.size (); i++)
    {
        s += v [i];
        count += direc.insert (s).second ? 1 : 0; //set返回一個pair<iterator,bool> bool指示插入是否成功   
 }
    
    return count;
}

int main ()
{
             freopen("d:\\input.txt","r",stdin);
  
    for (scanf ("%d", &T); TC <= T; TC++)
    {
        scanf ("%d %d", &N, &M);
        direc.clear ();
        int make = 0;
        char str [1000];
        
        for (int i = 0; i < N; i++)
        {
            do gets (str); while (strlen (str) == 0);//do gets 過濾回車空字符串
            insert (parse (str));
        }
        
        for (int i = 0; i < M; i++)
        {
            do gets (str); while (strlen (str) == 0);
            make += insert (parse (str));
        }
        
        printf ("Case #%d: %d\n", TC, make);
    }
    
    //system ("pause");
    return 0;
}
ploh的解法:
int main(void)
{freopen("d:\\input.txt","r",stdin);
  int T; cin >> T;
  for (int t = 1; t <= T; t++) {
    int ans = 0;
    set <string> have, want;
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
      string path; cin >> path;
      have.insert(path);
    }
    for (int i = 0; i < M; i++) {//用一個set保存所有需要加入的
      string path; cin >> path;
      want.insert(path);
      for (int j = 1; j < path.length(); j++)
    if (path[j] == '/')
      want.insert(path.substr(0, j));
    }
    for (set <string>::iterator it = want.begin(); it != want.end(); it++)//遍歷所有需要加入的,然后看是否存在
      if (!have.count(*it))
    ans++;
    printf("Case #%d: %d\n", t, ans);
  }
}


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久精彩免费视频| 免费在线成人| 国产精品区一区| 亚洲欧美日韩综合aⅴ视频| 亚洲图片欧洲图片av| 久久亚洲一区二区三区四区| 欧美一进一出视频| 欧美精品 日韩| 一区二区三区视频观看| 久热国产精品| 欧美成人免费小视频| 日韩亚洲欧美高清| 亚洲午夜性刺激影院| 韩日成人av| 亚洲国产小视频在线观看| 亚洲一区二区视频在线观看| 国产精品丝袜91| 欧美大片va欧美在线播放| 欧美日本韩国在线| 久久国产精品一区二区三区四区 | 亚洲国产成人高清精品| 亚洲第一黄网| 国产精品久久久久77777| 亚洲国产婷婷综合在线精品| 亚洲三级免费| 国语自产偷拍精品视频偷| 91久久精品国产91性色tv| 久久精品日韩欧美| 国产亚洲一级高清| 亚洲精品午夜精品| 国产一区二区三区久久久| 亚洲人成网站精品片在线观看| 久久免费精品视频| 在线观看欧美激情| 亚洲视频电影在线| 亚洲欧洲偷拍精品| 亚洲欧美日韩综合aⅴ视频| 国产精品欧美日韩一区二区| 亚洲电影免费| 国内外成人免费激情在线视频| 欧美一区=区| 欧美精品午夜视频| 欧美1区3d| 国产色视频一区| aⅴ色国产欧美| 91久久久久久久久| 久久久久免费| 久久国产精品99国产精| 欧美日韩国产在线播放| 欧美福利视频| 欧美日韩精品在线播放| 欧美成人有码| 红桃视频一区| 亚洲国产一区二区三区在线播 | 亚洲欧美日韩天堂一区二区| 亚洲啪啪91| 久久在线免费视频| 久久免费视频观看| 国产欧美欧洲在线观看| 99在线精品观看| 国产一区二区三区的电影| 美女脱光内衣内裤视频久久影院| 久久视频在线视频| 麻豆freexxxx性91精品| 国模吧视频一区| 亚洲国产精品一区二区第一页| 欧美久久电影| 日韩视频免费大全中文字幕| 亚洲精品影院| 欧美日韩国产一中文字不卡| 亚洲精品一品区二品区三品区| 国产精品一区二区黑丝| 亚洲欧美日韩国产另类专区| 午夜免费日韩视频| 国产日韩精品在线| 午夜亚洲一区| 免费在线国产精品| 亚洲激情电影中文字幕| 欧美日本三区| 亚洲视频在线观看一区| 久久狠狠亚洲综合| 精品不卡一区| 欧美电影在线| 在线中文字幕日韩| 久久婷婷久久| 国产精品任我爽爆在线播放| 午夜精品久久久久影视| 久久免费午夜影院| 亚洲激情小视频| 久久不射2019中文字幕| 欧美a级片网站| 在线视频精品一区| 国产女人水真多18毛片18精品视频| 亚洲电影专区| 亚洲欧美电影在线观看| 国内精品模特av私拍在线观看| 一区二区高清视频| 久久精品亚洲热| 国产精品都在这里| 欧美在线观看日本一区| 91久久在线观看| 先锋资源久久| 亚洲国产精品久久91精品| 久久成人综合视频| 91久久精品网| 久久精品国产免费| 亚洲精品一区二区三| 国产亚洲欧洲一区高清在线观看 | 欧美一区二区三区在线看| 欧美视频福利| 久久国产精品电影| 夜夜嗨一区二区| 牛牛国产精品| 久久精彩视频| 一本久久a久久免费精品不卡| 欧美大片一区二区| 久久国产乱子精品免费女| 99ri日韩精品视频| 欧美大成色www永久网站婷| 性欧美大战久久久久久久免费观看| 国产精品豆花视频| 亚洲一区二区视频在线| 小处雏高清一区二区三区 | 亚洲欧洲日本国产| 日韩亚洲欧美成人一区| 一区二区亚洲精品| 国产精品一级久久久| 国产精品99免费看 | 在线成人免费视频| 国产日本欧美一区二区三区| 欧美日本在线一区| 久久亚洲高清| 欧美亚洲一区二区在线| 亚洲一二三四久久| 一区二区三区四区精品| 久久精品1区| 午夜精品在线| 亚洲欧美一区二区精品久久久| 国产亚洲二区| 国产欧美亚洲一区| 国产日韩欧美一区| 国产亚洲综合性久久久影院| 国产精品热久久久久夜色精品三区| 欧美影片第一页| 久久精品99| 亚洲精品乱码久久久久| 欧美有码在线视频| 欧美一区2区三区4区公司二百| 在线精品亚洲| 国产精品高潮在线| 欧美婷婷在线| 国产精品一二三四区| 国产亚洲一区二区三区在线播放| 欧美成人一品| 欧美吻胸吃奶大尺度电影| 国产精品毛片高清在线完整版| 久久视频在线视频| 欧美顶级艳妇交换群宴| 久久aⅴ国产欧美74aaa| 久久久一本精品99久久精品66| 99av国产精品欲麻豆| 欧美阿v一级看视频| 亚洲福利免费| 中日韩美女免费视频网站在线观看| 免费短视频成人日韩| 亚洲国产视频一区二区| 日韩午夜视频在线观看| 亚洲夜间福利| 日韩午夜黄色| 亚洲欧美国产日韩天堂区| 亚洲精品在线二区| 亚洲自拍偷拍一区| 久久亚洲综合色一区二区三区| 亚洲午夜三级在线| 久久久亚洲高清| 欧美日韩美女一区二区| 国产日产精品一区二区三区四区的观看方式| 免费人成精品欧美精品| 国产精品v日韩精品| 激情亚洲成人| 亚洲专区免费| 免费短视频成人日韩| 久久亚洲一区| 一个色综合导航| 久久久夜精品| 国产麻豆成人精品| 亚洲精品自在久久| 久久久久久尹人网香蕉| 亚洲精品日韩欧美| 久久精品30| 国产精品人人做人人爽人人添| 国产精品大片wwwwww| 亚洲福利视频专区| 欧美在线观看www| 欧美高清在线观看| 91久久精品国产91性色| 欧美在线free| 国产精品日韩欧美综合 | 99精品视频一区| 久热这里只精品99re8久|