A Log Chopping
直接把每次总切割数算出来就行
#include<bits/stdc++.h>
using namespace std;
int t;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
int n;
int tot=0;
cin>>n;
for(int i=1;i<=n;i++){
int x;
cin>>x;
tot+=x-1;
}
if(tot%2==1) cout<<"errorgorn"<<'\n';
else cout<<"maomao90"<<'\n';
}
return 0;
}
B I love AAAB
注意翻译不太对,它并不是分割成好的字符串,而是从空串开始可以从任意位置插入好字符串,所以直接判第n为是不是B,然后顺着扫 判断B是否有对应的A就可以了
#include<bits/stdc++.h>
using namespace std;
string s;
int n;
bool check(string c,int len){
int now=0;
int ans=0;
if(s[len]!='B') return 0;
for(int i=1;i<=len;i++){
if(s[i]=='B'){
if(!now) return 0;
else{
ans++;
now--;
continue;
}
}
else{
now++;
}
}
return 1;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>s;
int len=s.size();
s=' '+s;
if(check(s,len)) cout<<"YES"<<'\n';
else cout<<"NO"<<'\n';
}
return 0;
}
C Unequal Array
很显然的可以想到有一种移的方式是要把两个要消除的部分拼起来,所以特判一下长度为3的区间就行
#include<bits/stdc++.h>
using namespace std;
int now=1e9+1;
const int maxn=2e5+5;
int a[maxn];
int t;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
int n;
cin>>n;
int ans=0;
for(int i=1;i<=n;i++) cin>>a[i];
int lst=0;
int noww=1;
int l=INT_MAX;
int r=0;
for(int i=2;i<=n;i++){
if(a[i]==a[i-1]){
l=min(l,i-1);
r=max(r,i);
}
}
if(r-l+1<=2) cout<<0<<'\n';
else if(r-l+1==3) cout<<1<<'\n';
else cout<<r-l+1-3<<'\n';
}
return 0;
}
标签:cout,CF1672,int,namespace,cin,len,tie
From: https://www.cnblogs.com/jt0007/p/17790390.html