日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴(lài)的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁(yè)編程開(kāi)發(fā)VC|VC++ → HDU 上的ACM字典樹(shù)參考代碼

      HDU 上的ACM字典樹(shù)參考代碼

      相關(guān)軟件相關(guān)文章發(fā)表評(píng)論 來(lái)源:本站整理時(shí)間:2010/12/8 8:40:48字體大小:A-A+

      作者:佚名點(diǎn)擊:242次評(píng)論:0次標(biāo)簽: HDU ACM 字典樹(shù)

      HduIn在杭電app3.21 官網(wǎng)安卓版
      • 類(lèi)型:網(wǎng)絡(luò)瀏覽大。5.1M語(yǔ)言:中文 評(píng)分:.0
      • 標(biāo)簽:
      立即下載
       要看論文準(zhǔn)備畢業(yè)設(shè)計(jì)了,好幾周都沒(méi)有搞ACM了,今天實(shí)在手癢了,就去hdu上溜達(dá)了一圈,挑幾個(gè)題做,于是乎就看到了這個(gè)題,典型的字典樹(shù)。

      題目要求輸出以某個(gè)字符串為前綴的word的數(shù)目,建立字典樹(shù)之后就是個(gè)簡(jiǎn)單的查詢(xún)了,為了性能采用了靜態(tài)字典樹(shù),由于不知道會(huì)有多少個(gè)單詞就猜了下感覺(jué)10w應(yīng)該夠了吧,提交上去access violation,明顯的越界訪(fǎng)問(wèn),修改為20W一樣出錯(cuò),后來(lái)火了,直接開(kāi)到50w過(guò)了,測(cè)試數(shù)據(jù)相當(dāng)狠呀。

      不多說(shuō)了,參考代碼如下。
      #include <stdio.h>
      #include <stdlib.h>
      struct node
      {
      int cnt;
      int childs[26];
      };
      int avail = 1;
      int cur = 0;
      struct node tree[500000];
      char buf[15];
      int main(void)
      {
      int i;
      int root;
      int index;
      int flag;
      /*freopen("in.txt", "r", stdin);*/
      while (fgets(buf, 15, stdin) != NULL && buf[0] != '\n')
      {
      i = 0;
      root = 0;
      while (buf[i] != '\n')
      {
      index = buf[i]-'a';
      if (tree[root].childs[index] == 0)
      {
      tree[root].childs[index] = avail++;
      }
      ++tree[tree[root].childs[index]].cnt;
      root = tree[root].childs[index];
      ++i;
      }
      }

      while (fgets(buf, 15, stdin) != NULL && buf[0] != '\n')
      {
      i = 0;
      root = 0;
      flag = 1;
      while (buf[i] != '\n')
      {
      index = buf[i] - 'a';
      if (tree[root].childs[index] == 0)
      {
      flag = 0;
      break;
      }
      root = tree[root].childs[index];
      ++i;
      }
      printf("%d\n", flag == 1 ? tree[root].cnt : 0);
      }
      return 0;
      }

        相關(guān)評(píng)論

        閱讀本文后您有什么感想? 已有人給出評(píng)價(jià)!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過(guò)難過(guò)
        • 5 囧
        • 3 圍觀圍觀
        • 2 無(wú)聊無(wú)聊

        熱門(mén)評(píng)論

        第 1 樓 上海浦東新有線(xiàn)通 網(wǎng)友 客人 發(fā)表于: 2010/12/19 17:22:01
        能說(shuō)明說(shuō)明意思那最好了

        支持( 0 ) 蓋樓(回復(fù))

        最新評(píng)論

        第 1 樓 上海浦東新有線(xiàn)通 網(wǎng)友 客人 發(fā)表于: 2010/12/19 17:22:01
        能說(shuō)明說(shuō)明意思那最好了

        支持( 0 ) 蓋樓(回復(fù))

        發(fā)表評(píng)論 查看所有評(píng)論(0)

        昵稱(chēng):
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過(guò)審核才能顯示)