B. Balls of Buma
祖玛游戏,如果我们只射出一个子弹可以把所有都消掉的话那么我们分段的数量一定是一个奇数,然后对称的地方的种类是相同的并且对称位置相加后的数字一定是大于3的。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56#include <bits/stdc++.h> //#define int long long using namespace std; const int N=3e5+10; int a[N],pos[N]; char s[N]; void solve() { cin>>s+1; int cnt=0,num=1; int len=strlen(s+1); s[len+1]='#'; len++; a[1]=1; for(int i=2;i<=len;i++){ if(s[i]!=s[i-1]){ a[i]=1; pos[++cnt]=i-1; }else { a[i]=a[i-1]+1; } } // for(int i=1;i<=len;i++) printf("%d ",a[i]); // puts(""); // for(int i=1;i<=cnt;i++) printf("%d ",pos[i]); // puts(""); if(cnt%2==0) { puts("0"); return; } for(int i=1;i<=cnt;i++){ if(i==(cnt+1)/2){ if(a[pos[i]]+1>2) printf("%dn",a[pos[i]]+1); else printf("0n"); return; } else if(s[pos[i]]!=s[pos[cnt-i+1]]||a[pos[i]]+a[pos[cnt-i+1]]<3){ printf("0n"); return; } } } signed main(){ // init(); solve(); #ifndef ONLINE_JUDGE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.n"; #endif return 0; }
B、Boring Non-Palindrome
长度只有5000找最长回文后缀。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38#include <bits/stdc++.h> //#define int long long using namespace std; const int N=3e5+10; string a; int check(int pos) { int l=pos,r=a.length()-1; while(l<=r){ if(a[l]==a[r]) l++,r--; else return 0; } return 1; } void solve() { cin>>a; int pos; for(int i=0;i<a.length();i++){ if(check(i)){ pos=i; break; } } cout<<a; for(int i=pos-1;i>=0;i--) cout<<a[i]; puts(""); } signed main(){ // init(); solve(); #ifndef ONLINE_JUDGE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.n"; #endif return 0; }
最后
以上就是高挑黄蜂最近收集整理的关于2020-9-21训练B. Balls of BumaB、Boring Non-Palindrome的全部内容,更多相关2020-9-21训练B.内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复