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 }
View Code

相关文章:

  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2022-01-06
  • 2021-12-04
  • 2021-12-22
猜你喜欢
  • 2021-08-31
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-04-12
  • 2022-12-23
相关资源
相似解决方案