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

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>
            一区二区三区导航| 在线观看亚洲视频| 国产日韩欧美视频| 久久网站热最新地址| 一卡二卡3卡四卡高清精品视频| 久久久亚洲欧洲日产国码αv| 夜夜夜久久久| 亚洲日本欧美日韩高观看| 亚洲电影激情视频网站| 狠狠狠色丁香婷婷综合激情| 国产精品一区视频网站| 免费亚洲婷婷| 亚洲视频你懂的| 99精品国产一区二区青青牛奶| 久久精品中文字幕一区| 久久综合色婷婷| 另类图片综合电影| 香蕉国产精品偷在线观看不卡| 亚洲香蕉成视频在线观看| 日韩一级片网址| 国产日韩精品一区二区| 国产一区日韩欧美| 亚洲福利视频在线| 伊人夜夜躁av伊人久久| 国产午夜精品美女视频明星a级 | 亚洲黄色免费| 亚洲国产一区二区在线| 免费一级欧美片在线观看| 麻豆成人在线| 亚洲国产高清高潮精品美女| 亚洲精品一区二区在线观看| 亚洲天堂网站在线观看视频| 亚洲欧美激情精品一区二区| 久久精品中文字幕免费mv| 亚洲欧美另类中文字幕| 亚洲日本成人在线观看| 亚洲午夜小视频| 亚洲欧美在线免费观看| 久久天天躁狠狠躁夜夜爽蜜月| 欧美国产日本在线| 国产精品乱人伦一区二区| 国产日韩久久| 亚洲乱码国产乱码精品精| 亚洲综合第一| 免费不卡欧美自拍视频| 亚洲精品永久免费| 欧美与欧洲交xxxx免费观看| 欧美久久久久久蜜桃| 国产日韩一区二区| 亚洲三级免费电影| 亚洲精品在线一区二区| 亚洲深夜激情| 亚洲欧美日韩国产一区二区三区| 欧美专区在线观看一区| 亚洲激情影视| 久久精品首页| 国产精品久久久久久久久借妻| 影音先锋亚洲视频| 午夜精品免费在线| 亚洲黄色有码视频| 久久久久久**毛片大全| 国产精品青草久久久久福利99| 亚洲国产精品va在线看黑人动漫 | 欧美成人免费小视频| 国产视频亚洲精品| 老司机免费视频一区二区三区| 欧美肉体xxxx裸体137大胆| 国产日产欧产精品推荐色| 亚洲午夜激情| 91久久精品国产91久久性色tv| 欧美一区二区三区视频在线| 欧美三区在线| 中文亚洲欧美| 国产一区 二区 三区一级| 国产色产综合产在线视频| 一区免费视频| 亚洲专区在线| 乱码第一页成人| 午夜激情综合网| 欧美成人tv| 国产婷婷精品| 欧美一区二区三区久久精品茉莉花 | 亚洲国产婷婷| 欧美激情按摩在线| 日韩亚洲国产精品| 亚洲精品乱码| 欧美日韩三级在线| 亚洲一区二区三区在线视频| 午夜一区不卡| 亚洲无亚洲人成网站77777 | 亚洲一区欧美一区| 日韩五码在线| 麻豆精品视频在线| 亚洲精品小视频| 亚洲激情电影在线| 国产精品theporn88| 午夜精品久久久久影视| 亚洲欧美一区二区视频| 国产日韩欧美中文| 久久夜色精品国产| 欧美成人免费在线视频| 亚洲视频免费| 欧美一区1区三区3区公司| 欧美日本二区| 亚洲精品免费电影| 国产精品99久久久久久久久| 国产精品久久久久婷婷| 久久国产手机看片| 欧美α欧美αv大片| 一区二区三区日韩| 欧美亚洲视频一区二区| 黄色成人片子| 日韩亚洲视频在线| 国产日韩av一区二区| 欧美成人高清视频| 欧美日韩人人澡狠狠躁视频| aa亚洲婷婷| 亚洲欧美在线一区| 亚洲国产小视频| 亚洲欧美www| 亚洲激情中文1区| 一区二区三区日韩在线观看| 国产日韩欧美日韩| 亚洲韩日在线| 国产综合网站| 99这里有精品| 国产精品综合av一区二区国产馆| 亚洲一二三四久久| 久久综合伊人77777| 亚洲欧美日韩国产综合| 久久综合五月| 国产喷白浆一区二区三区| 亚洲国产成人高清精品| 日韩亚洲欧美一区| 在线观看欧美一区| 亚洲国产人成综合网站| 欧美精品导航| 欧美不卡视频| 国产视频一区三区| 亚洲视频免费看| 一区二区欧美激情| 免费美女久久99| 久久亚洲视频| 国产日韩欧美日韩| 亚洲性xxxx| 亚洲在线电影| 久久久久久尹人网香蕉| 欧美中文在线观看国产| 国产精品高精视频免费| 亚洲国产精品一区二区www在线| 国产日韩在线一区二区三区| 一区二区三区www| 一本综合久久| 久久婷婷久久| 欧美成人免费va影院高清| 亚洲精选成人| 国产精品美女999| 欧美亚洲专区| 亚洲第一狼人社区| 亚洲愉拍自拍另类高清精品| 国产日韩在线亚洲字幕中文| 久久精品首页| 亚洲狼人综合| 性欧美暴力猛交另类hd| 经典三级久久| 欧美日韩视频在线一区二区观看视频| av成人黄色| 久久欧美肥婆一二区| 亚洲精品美女| 国产日韩精品久久久| 欧美chengren| 亚洲欧美日韩人成在线播放| 欧美1区2区视频| 亚洲尤物视频网| 一区在线视频观看| 欧美日韩综合视频| 久久综合五月| 亚洲一区二区伦理| 亚洲福利视频专区| 久久久久久久一区| 亚洲在线免费| 亚洲日本va在线观看| 国产午夜精品美女毛片视频| 欧美日本韩国| 另类成人小视频在线| 亚洲制服少妇| 亚洲卡通欧美制服中文| 免费人成网站在线观看欧美高清| 亚洲综合色视频| 最新亚洲一区| 狠狠色狠狠色综合日日tαg| 欧美日韩免费一区二区三区视频| 久久精品二区| 午夜精品久久久久久| 99视频一区二区| 亚洲国产欧美一区二区三区同亚洲| 久久久久国产精品一区| 亚洲欧美日韩精品久久亚洲区| 亚洲伦理中文字幕| 在线观看亚洲视频|