日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

POJ 2418 Hardwood Species(trie 树)

發布時間:2023/11/27 生活经验 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 2418 Hardwood Species(trie 树) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接

開始想用map的,字典序不會搞,還是老老實實的用trie樹把。好久沒寫了,忘得差不多了。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <map>
 6 #include <cmath>
 7 #include <string>
 8 #include <queue>
 9 #include <vector>
10 #include <algorithm>
11 using namespace std;
12 struct node
13 {
14     int data;
15     struct node *next[129];
16 };
17 int num = 0;
18 char o[51];
19 struct node *build()
20 {
21     int i;
22     node *p;
23     p = new node;
24     p -> data = 0;
25     for(i = 0; i <= 128; i ++)
26         p -> next[i] = NULL;
27     return p;
28 }
29 void insert(struct node *head,char *str)
30 {
31     int i,len;
32     len = strlen(str);
33     node *p;
34     p = head;
35     for(i = 0; i < len; i ++)
36     {
37         if(p->next[str[i]] == NULL)
38         {
39             p->next[str[i]] = build();
40         }
41         p = p->next[str[i]];
42     }
43     p -> data ++;
44 }
45 void dfs(struct node *head,int step)
46 {
47     int i;
48     node *p;
49     p = head;
50     if(p->data > 0)
51     {
52         o[step] = '\0';
53         printf("%s %.4lf\n",o,p->data*100.0/num);
54     }
55     for(i = 0; i <= 128; i ++)
56     {
57         if(p->next[i] != NULL)
58         {
59             o[step] = i;
60             dfs(p->next[i],step+1);
61         }
62     }
63 }
64 int main()
65 {
66     char p[51];
67     node *head;
68     head = build();
69     while(gets(p) != 0)
70     {
71         insert(head,p);
72         num ++;
73     }
74     dfs(head,0);
75     return 0;
76 }

?

轉載于:https://www.cnblogs.com/naix-x/archive/2013/01/18/2866930.html

總結

以上是生活随笔為你收集整理的POJ 2418 Hardwood Species(trie 树)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。