标签:alt sample limit target php follow cat content stat
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Statistic | Submit | Discuss | Note
http://acm.hdu.edu.cn/showproblem.php?pid=1671
1 #include<bits/stdc++.h> 2 3 using namespace std; 4 5 int n, t; 6 bool ans; 7 const int MAXN = 110000; 8 int g[MAXN][15], f[MAXN], gx, w[MAXN]; 9 10 bool add (int u, string s, int x) { 11 if (x >= s.length()) return 0; 12 w[u] = 1; 13 if (f[g[u][s[x] - ‘0‘]]) { 14 return 0; 15 } 16 else { 17 if (!g[u][s[x] - ‘0‘]) g[u][s[x] - ‘0‘] = ++gx; 18 if (x == s.length() - 1) { 19 if (w[g[u][s[x] - ‘0‘]]) return 0; 20 f[g[u][s[x] - ‘0‘]] = 1; 21 w[g[u][s[x] - ‘0‘]] = 1; 22 return 1; 23 } 24 else { 25 return add(g[u][s[x] - ‘0‘], s, x + 1); 26 } 27 } 28 } 29 30 int main() { 31 cin >> t; 32 while (t--) { 33 ans = 1; 34 cin >> n; 35 memset(f, 0, sizeof(f)); 36 memset(g, 0, sizeof(g)); 37 memset(w, 0, sizeof(w)); 38 gx = 1; 39 while (n--) { 40 string s; 41 cin >> s; 42 ans = min(ans, add(1, s, 0)); 43 } 44 if (ans) { 45 cout << "YES\n"; 46 } 47 else { 48 cout << "NO\n"; 49 } 50 } 51 return 0; 52 }
1 #include<bits/stdc++.h> 2 3 using namespace std; 4 5 string s[10001]; 6 7 int main() { 8 int t; 9 cin >> t; 10 while (t--) { 11 int n; 12 cin >> n; 13 for (int i = 1; i <= n; ++i) cin >> s[i]; 14 sort(s + 1, s + 1 + n); 15 bool tf = 1; 16 for (int i = 2; i <= n && tf; ++i) { 17 if (s[i].length() > s[i - 1].length()) { 18 bool x = 1; 19 for (int j = 0; j < s[i - 1].length(); ++j) { 20 if (s[i - 1][j] != s[i][j]) { 21 x = 0; 22 break; 23 } 24 } 25 if (x) tf = 0; 26 } 27 } 28 if (tf) cout << "YES\n"; 29 else cout << "NO\n"; 30 } 31 return 0; 32 }
标签:alt sample limit target php follow cat content stat
原文地址:https://www.cnblogs.com/m-m-m/p/9066091.html