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

Google code jam Round1B

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

A 簡(jiǎn)單的模擬 ,不過(guò)我寫的很麻煩

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分隔各級(jí)目錄
            istringstream iss (s);
            while (iss >> s) {
                ss.pb (s);
            }

            s = "";
            REP (i, ss.size ())
            {
                s = s+"/"+ss[i];
                if (S.find(s) == S.end())//依次加入各級(jí)目錄,/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.
告訴我們?nèi)绻?a/b被list存在,那么/a也一定被list出來(lái)了 ,所以上面代碼可以不去分隔處理已經(jīng)給出的目錄
yuhch123的解法
struct node {
   map <string, node *> sons;//每個(gè)節(jié)點(diǎn),用map實(shí)現(xiàn)兒子節(jié)點(diǎn)
};
node *root;//一個(gè)根節(jié)點(diǎn)
int T;
int N, M;
char tmp[100005];
int ans = 0;
void insert(node *cnt, char *tmp) {//在節(jié)點(diǎn)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()) {//如果沒有這子樹,則創(chuàng)建子樹
      ans ++;//需要一次mkdir 
      struct node *tmp2 = new node();
      cnt -> sons[str] = tmp2;
   }
   insert(cnt -> sons[str], tmp + i);// 遞歸創(chuàng)建子樹
}
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返回一個(gè)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 過(guò)濾回車空字符串
            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++) {//用一個(gè)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);
  }
}


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   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>
            亚洲婷婷综合色高清在线| 久久久精品tv| 久久久av水蜜桃| 欧美专区中文字幕| 欧美一区二区视频观看视频| 亚洲自啪免费| 欧美在线视屏| 免费成人毛片| 99re6热在线精品视频播放速度 | 欧美国产先锋| 亚洲精品中文字| 性做久久久久久久久| 久久精品毛片| 欧美香蕉视频| 亚洲第一主播视频| 一区二区欧美亚洲| 欧美一区二区性| 欧美成人精品高清在线播放| 亚洲精品国产精品久久清纯直播 | 新片速递亚洲合集欧美合集| 老司机午夜精品| 国产精品久久激情| 在线观看91精品国产麻豆| 一本色道**综合亚洲精品蜜桃冫| 亚洲欧美在线高清| 亚洲电影下载| 久久精品首页| 国产精品一区2区| 日韩视频一区二区在线观看 | 最新亚洲激情| 久久精品国产999大香线蕉| 欧美日韩成人免费| 国内精品视频在线观看| 制服丝袜激情欧洲亚洲| 美女黄网久久| 午夜精品久久久久久久白皮肤 | 久久久久国色av免费观看性色| 91久久精品网| 久久视频在线看| 亚洲一区二区三区免费在线观看| 亚洲精品一区二区三区99| 翔田千里一区二区| 日韩视频第一页| 欧美大片一区二区| 在线日韩日本国产亚洲| 久久精品国产91精品亚洲| av成人免费在线观看| 欧美激情一区二区三区| 亚洲国产婷婷| 欧美激情五月| 免费日本视频一区| 亚洲电影免费观看高清完整版| 久久久久国产精品厨房| 欧美一区二区性| 国内免费精品永久在线视频| 久久久精品国产免大香伊 | 欧美成人蜜桃| 亚洲国产一二三| 欧美高清不卡| 欧美不卡高清| 日韩视频免费看| 日韩视频在线一区二区三区| 欧美激情久久久久| 99日韩精品| 夜夜精品视频| 国产精品亚洲激情| 欧美在线91| 久久精品国产亚洲a| 黄色国产精品| 欧美激情亚洲综合一区| 欧美成年人视频网站| 亚洲精选中文字幕| 亚洲精品国久久99热| 欧美日韩在线视频一区| 午夜国产精品视频免费体验区| 亚洲一区二区三区成人在线视频精品 | 亚洲激情影视| 亚洲乱码日产精品bd| 国产精品热久久久久夜色精品三区| 欧美在线视频在线播放完整版免费观看 | 亚洲日本成人| 国产精品久久久久久久9999| 欧美在线日韩| 免费成人黄色| 亚洲永久精品国产| 久久久免费精品视频| 亚洲精品1区| 亚洲无吗在线| 亚洲高清精品中出| 亚洲视频欧美在线| 在线精品视频一区二区三四| 亚洲激情在线播放| 欧美成人影音| 国产一区二区三区日韩| 欧美在线看片a免费观看| 久久精品亚洲精品国产欧美kt∨| 亚洲激情视频| 午夜免费久久久久| 亚洲最新在线视频| 久久久高清一区二区三区| 一级日韩一区在线观看| 欧美在线观看一二区| 日韩视频三区| 久久福利毛片| 亚洲自拍另类| 欧美.日韩.国产.一区.二区| 性欧美暴力猛交69hd| 欧美多人爱爱视频网站| 久久蜜桃香蕉精品一区二区三区| 欧美日韩视频| 亚洲国产综合在线看不卡| 国产亚洲欧美日韩精品| 中国成人亚色综合网站| aa国产精品| 免费视频一区| 开心色5月久久精品| 国产酒店精品激情| 一本色道久久综合精品竹菊| 最新中文字幕一区二区三区| 久久成人在线| 久久久免费av| 国产日韩欧美二区| 亚洲视屏在线播放| 亚洲一二三区在线| 欧美日韩a区| 亚洲国产天堂久久综合网| 亚洲福利视频一区二区| 久久久久国产精品麻豆ai换脸| 午夜视频久久久| 国产精品视频yy9299一区| 亚洲午夜激情| 欧美亚洲在线播放| 国产日韩欧美在线| 午夜性色一区二区三区免费视频| 亚洲一区二区毛片| 国产精品白丝av嫩草影院| 在线视频一区二区| 亚洲欧美另类国产| 亚洲福利视频一区二区| 欧美韩国日本综合| 欧美高清在线一区| 亚洲国产日韩欧美| 免费欧美高清视频| 亚洲激情视频在线| 日韩视频在线一区| 欧美噜噜久久久xxx| 亚洲人成网站精品片在线观看| 亚洲人成亚洲人成在线观看| 欧美韩国日本一区| 一本色道久久综合狠狠躁篇怎么玩| 亚洲一区二区三区免费观看| 国产精品一二三| 欧美一区午夜精品| 蜜臀a∨国产成人精品| 亚洲激情av| 欧美午夜无遮挡| 欧美亚洲免费电影| 欧美电影在线观看完整版| 99精品视频网| 国产女人水真多18毛片18精品视频| 亚洲欧洲一区二区三区久久| 免费观看日韩| 亚洲毛片在线观看| 欧美一区二区三区视频| 在线不卡亚洲| 欧美视频成人| 久久精品一区蜜桃臀影院| 亚洲国产一区二区三区高清| 性欧美激情精品| 亚洲人体影院| 国产日韩欧美综合精品| 欧美88av| 午夜在线a亚洲v天堂网2018| 亚洲高清视频一区| 午夜在线一区| 亚洲欧洲精品成人久久奇米网| 欧美性猛交xxxx免费看久久久 | 亚洲综合第一页| 亚洲电影免费在线观看| 久久黄金**| 亚洲欧美一区二区三区久久 | 亚洲承认在线| 久久狠狠亚洲综合| 夜夜精品视频| 在线观看欧美日本| 国产精品久久久久999| 猫咪成人在线观看| 欧美资源在线| 亚洲欧美日韩精品久久奇米色影视 | 欧美一级视频| 9l国产精品久久久久麻豆| 国模 一区 二区 三区| 国产精品va在线| 欧美日韩国产三区| 欧美高清一区| 欧美成人免费播放| 久久久久天天天天| 欧美一级网站| 欧美中日韩免费视频| 欧美诱惑福利视频|