[POJ3630]Phone List (Tire)
阿新 • • 發佈:2019-01-06
class ostream inf ret n) code problem ack har
題意
trie字典樹模板
LOJ有中文翻譯https://loj.ac/problem/10049
思路
TIRE
代碼
之前在LOJ上做過
直接交了
#include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<map> #include<queue> #include<stack> #include<cstring> #include<string> usingnamespace std; #define N 100000+5 int T,n,tot; int ch[N][15]; bool bo[N]; char s[15]; bool insert(char *s) { int len = strlen(s); int u = 1; bool fl = false; for (int i = 0; i < len; i++) { int c = s[i] - 48; if (!ch[u][c]) { ch[u][c] = ++tot; }else { if (i == len-1) { fl = true; } } u = ch[u][c]; if (bo[u]) fl = true; } bo[u] = true; return fl; } int main() { scanf("%d", &T); while (T--) { scanf("%d",&n); tot= 1; memset(ch, 0, sizeof(ch)); memset(bo, false, sizeof(bo)); bool ans = false; for (int i = 1; i <= n; i++) { scanf("%s", s); if (insert(s)) ans = true; } if (!ans) puts("YES"); else puts("NO"); } return 0; }
[POJ3630]Phone List (Tire)