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

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>
            国产无遮挡一区二区三区毛片日本| 国产在线视频欧美| 亚洲日本va午夜在线影院| 免费看的黄色欧美网站| 久久午夜视频| 亚洲激情第一页| 亚洲人成在线播放网站岛国| 欧美激情一区二区三区成人| 妖精视频成人观看www| 99在线|亚洲一区二区| 国产精品美女久久久浪潮软件| 午夜精品久久久久99热蜜桃导演| 午夜精品一区二区三区在线| 国内精品久久久久影院色| 欧美 日韩 国产一区二区在线视频 | 亚洲午夜av在线| 一本久久青青| 国产在线播放一区二区三区| 亚洲国产精品va在线观看黑人| 欧美精品在线一区二区三区| 午夜视频在线观看一区| 久久精品人人做人人爽| 亚洲欧洲精品一区| 亚洲午夜精品久久久久久app| 国内揄拍国内精品久久| 亚洲国产黄色片| 国产精品一区二区女厕厕| 欧美不卡三区| 国产欧美午夜| 亚洲精品在线免费观看视频| 国内久久视频| 日韩特黄影片| 亚洲国产精品久久久久秋霞影院| 99精品视频网| 亚洲人成网站在线观看播放| 亚洲欧美在线一区| 亚洲美女淫视频| 久久精品欧美日韩精品| 亚洲午夜在线观看视频在线| 久久这里只有| 午夜精品短视频| 欧美巨乳在线观看| 美日韩精品视频免费看| 国产精品毛片在线| 久久久美女艺术照精彩视频福利播放| 欧美www视频| 午夜精品久久久久久久久久久久久 | 玖玖精品视频| 久久国产一区二区| 欧美午夜精品久久久久久浪潮 | 99这里只有久久精品视频| 久久国产精品黑丝| 欧美一级黄色网| 欧美视频一区在线观看| 91久久精品一区| 亚洲国产欧洲综合997久久| 欧美一区二区三区男人的天堂| 亚洲视频福利| 欧美色图五月天| 日韩视频三区| 亚洲天堂男人| 欧美日韩视频一区二区| 亚洲精品你懂的| 亚洲黄色有码视频| 裸体素人女欧美日韩| 理论片一区二区在线| 韩日精品在线| 久久久久久亚洲精品杨幂换脸| 久久久久天天天天| 国产一区二区三区四区| 久久精品99国产精品酒店日本| 久久―日本道色综合久久| 国产日韩精品一区二区| 久久精品国产99国产精品| 久久午夜电影网| 亚洲人成久久| 欧美色视频日本高清在线观看| 一区二区三区国产在线| 亚洲免费一级电影| 国产日本精品| 麻豆精品视频在线观看视频| 欧美激情影院| 亚洲在线观看视频| 国产亚洲欧美在线| 裸体素人女欧美日韩| 亚洲精品国产精品国自产观看| 亚洲一区综合| 国内精品久久久久久久影视蜜臀 | 亚洲欧美日韩国产一区二区三区| 久久精品30| 亚洲高清二区| 国产精品电影在线观看| 欧美一区久久| 最新亚洲一区| 久久精品一二三| 亚洲久久一区| 国产亚洲精品久久飘花| 免费成人黄色片| 亚洲一区在线直播| 欧美大片免费看| 亚洲在线视频| 亚洲国产精品一区二区第四页av | 精品成人一区二区| 欧美精品情趣视频| 香港久久久电影| 亚洲国产精品成人久久综合一区| 亚洲综合色婷婷| 在线免费观看欧美| 国产精品久久一区二区三区| 久久综合伊人77777麻豆| 在线亚洲免费| 亚洲国产婷婷综合在线精品| 久久av一区二区| 日韩一级二级三级| 激情久久久久| 国产精品入口日韩视频大尺度| 免费观看国产成人| 亚洲一区免费网站| 日韩视频一区二区三区| 免费永久网站黄欧美| 欧美一级片一区| 亚洲小说欧美另类婷婷| 亚洲激情小视频| 一区精品久久| 国产婷婷成人久久av免费高清| 欧美日韩国产一级| 欧美成人精品一区| 久久偷窥视频| 久久精品综合网| 亚洲欧美日韩一区二区三区在线| 亚洲日本一区二区| 欧美激情一区二区三区| 裸体素人女欧美日韩| 久久国产一区二区三区| 欧美一级久久久| 欧美亚洲一区三区| 香蕉久久精品日日躁夜夜躁| 在线综合视频| 一区二区激情| 一区二区三区高清在线 | 国产女人精品视频| 国产精品专区第二| 国产欧美日韩在线视频| 国产精品毛片a∨一区二区三区| 欧美日韩精品综合| 欧美日韩不卡一区| 欧美日本不卡视频| 欧美三区美女| 国产精品久久久久毛片软件| 国产精品美女主播| 国产精品日韩一区二区三区| 国产精品视频久久| 国产日韩欧美高清免费| 国产字幕视频一区二区| 一区精品在线播放| 亚洲精品欧美| 亚洲一区二区三区激情| 亚洲免费网址| 久久精品国产视频| 美日韩精品视频免费看| 亚洲成色999久久网站| 亚洲精品国产精品乱码不99 | 欧美国产亚洲另类动漫| 欧美激情在线观看| 日韩视频二区| 亚洲影院在线观看| 久久久亚洲影院你懂的| 欧美成人免费全部观看天天性色| 欧美日韩国产精品一区二区亚洲| 欧美午夜一区| 韩日在线一区| 一区二区三区精品在线| 欧美一区二区三区另类| 欧美mv日韩mv国产网站app| 亚洲国产精品高清久久久| 亚洲视频1区| 久久久午夜视频| 欧美色综合天天久久综合精品| 欧美日一区二区三区在线观看国产免| 国产精品乱码| 亚洲激情视频在线| 欧美一区二区三区免费大片| 欧美国产欧美综合| 亚洲小视频在线| 女人天堂亚洲aⅴ在线观看| 国产精品拍天天在线| 亚洲国产精品久久| 午夜精品av| 91久久夜色精品国产九色| 午夜久久久久久| 欧美日韩在线视频一区二区| 国内精品视频在线观看| 亚洲一区二区成人在线观看| 农夫在线精品视频免费观看| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 欧美激情第五页| 午夜精品网站| 国产精品白丝黑袜喷水久久久| 亚洲国产毛片完整版 | 国产一区二区三区四区三区四|