A - Pattern String
留坑。
B - Bazinga
题意:找一个最大的i,使得前i - 1个字符串中至少不是它的子串
思路:暴力找,如果有一个串已经符合条件,就不用往上更新
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define N 510 5 6 int t, n; 7 int vis[N]; 8 string s[N]; 9 10 int main() 11 { 12 ios::sync_with_stdio(false); 13 int t; 14 cin >> t; 15 for(int cas = 1; cas <= t; ++cas) 16 { 17 cin >> n; 18 memset(vis, 0, sizeof vis); 19 for(int i = 1; i <= n; ++i) cin >> s[i]; 20 int ans = -1; 21 for(int i = 1; i <= n; ++i) 22 { 23 for(int j = i + 1; j <= n; ++j) 24 { 25 if(!vis[j]) 26 { 27 int tmp = s[j].find(s[i]); 28 if(tmp == -1) 29 { 30 vis[j] = 1; 31 ans = max(ans, j); 32 } 33 else break; 34 } 35 } 36 } 37 cout << "Case #" << cas << ": " << ans << endl; 38 } 39 return 0; 40 }