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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj 2513 Colored Sticks( 字典树哈希+ 欧拉回路 + 并查集)

發(fā)布時(shí)間:2024/6/14 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj 2513 Colored Sticks( 字典树哈希+ 欧拉回路 + 并查集) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目:http://poj.org/problem?id=2513

參考博客:http://blog.csdn.net/lyy289065406/article/details/6647445

http://www.cnblogs.com/LK1994/p/3263462.html

1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 #include<stack> 6 #include<queue> 7 #include<iomanip> 8 #include<cmath> 9 #include<map> 10 #include<vector> 11 #include<algorithm> 12 #define N 500010 13 using namespace std; 14 15 int degree[N],bin[N],id = 1; 16 17 struct tree 18 { 19 int flag,id; 20 struct tree* next[26]; 21 }*root; 22 struct tree* creat() 23 { 24 struct tree *p=(struct tree*)malloc(sizeof(struct tree)); 25 p->flag =0; 26 for(int i = 0; i < 26; i++) 27 p->next[i] = NULL; 28 return p; 29 } 30 31 int find(int x) 32 { 33 if(bin[x] != x) 34 bin[x] = find(bin[x]); 35 return bin[x]; 36 } 37 38 int hash(char s[]) 39 { 40 struct tree *p = root; 41 for(int i = 0; s[i]; i++) 42 { 43 if(p->next[s[i]-'a'] == NULL) 44 p->next[s[i]-'a'] = creat(); 45 p = p->next[s[i]-'a']; 46 } 47 if(p->flag != 1) 48 { 49 p->flag = 1; 50 p->id = id++; 51 } 52 return p->id; 53 } 54 55 int check() 56 { 57 int sum = 0; 58 int x = find(1); 59 for(int i = 2; i < id; i++) 60 if(find(i) != x) 61 return 0; 62 for(int i = 1; i < id; i++) 63 { 64 if(degree[i]%2) 65 sum++; 66 } 67 if(sum == 0 || sum == 2) 68 return 1; 69 return 0; 70 } 71 72 int main() 73 { 74 int u,v,x,y; 75 char s1[15],s2[15]; 76 memset(degree,0,sizeof(degree)); 77 for(int i=1; i<=500000; i++) 78 bin[i]=i; 79 root=creat(); 80 while(scanf("%s %s",s1,s2)!=EOF) 81 { 82 u =hash(s1); v =hash(s2); 83 degree[u]++; degree[v]++; 84 x=find(u); 85 y=find(v); 86 if(x!=y) 87 bin[x]=y; 88 } 89 if(check()) printf("Possible\n"); 90 else printf("Impossible\n"); 91 return 0; 92 }

?

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/bfshm/p/3279871.html

總結(jié)

以上是生活随笔為你收集整理的poj 2513 Colored Sticks( 字典树哈希+ 欧拉回路 + 并查集)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。