本文主要是介绍Codeforces Round 923 (Div. 3) A - E,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
CF1927A Make it White
代码如下:
//朴素版
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 200005;
#define inf 0x7fffffff
void solve()
{ll n;cin>>n;string a;cin>>a;ll x=-1,y=0;a=' '+a;for(ll i=1;i<=n;i++){if(a[i]=='B'&&x==-1){x=i;break;}}for(ll i=n;i>=1;i--){if(a[i]=='B'){y=i;break;}}cout<<y-x+1<<'\n';
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);ll t;cin>>t;while(t--) solve();return 0;
}
CF1927B Following the String
代码如下:
//朴素版
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 200005;
#define inf 0x7fffffff
void solve()
{ll n;cin>>n;vector<ll>a(n+1),b(n+1);vector<char>s(n+1);for(ll i=1;i<=n;i++){cin>>a[i];}char e='a'-1;while(1){e++;ll x=0;for(ll i=1;i<=n;i++){if(a[i]==x&&!b[i]){x++;b[i]=1;s[i]=e;}}if(x==0) break;}for(ll i=1;i<=n;i++) cout<<s[i];cout<<'\n';
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);ll t;cin>>t;while(t--) solve();return 0;
}
CF1927C Choose the Different Ones!
代码如下:
//朴素版
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 400001;
#define inf 0x7fffffff
void solve()
{ll n,m,k;cin>>n>>m>>k;vector<ll>a(k+1),b(k+1),vis(k+1);ll q=0,e=0;for(ll i=0;i<n;i++){ll x;cin>>x;if(x<=k&&a[x]==0){a[x]=1;vis[x]=1;q++;}}for(ll i=0;i<m;i++){ll x;cin>>x;if(x<=k&&b[x]==0){b[x]=1;vis[x]=1;e++;}}for(ll i=1;i<=k;i++){if(vis[i]==0){cout<<"NO"<<'\n';return;}}if(q>=k/2&&e>=k/2) cout<<"YES"<<'\n';else cout<<"NO"<<'\n';
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);ll t;cin>>t;while(t--) solve();return 0;
}
CF1927D Find the Different Ones!
代码如下:
//朴素版
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 200005;
#define inf 0x7fffffff
void solve()
{ll n;cin>>n;vector<ll>a(n+2),b(n+2),z(n+2),y(n+2),vis(n+1);for(ll i=1;i<=n;i++){cin>>a[i];b[i]=b[i-1]+a[i];}ll x=n+1;for(ll i=n-1;i>=1;i--){if(a[i]==a[i+1]){y[i]=x;}else {x=i+1;y[i]=x;}}ll q;cin>>q;while(q--){ll x,yy;cin>>x>>yy;if(y[x]>yy){cout<<-1<<' '<<-1<<'\n';}else {cout<<x<<' '<<y[x]<<'\n';}}cout<<'\n';
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);ll t;cin>>t;while(t--) solve();return 0;
}
CF1927E Klever Permutation
代码如下:
//朴素版
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 200005;
#define inf 0x7fffffff
void solve()
{ll n,k;cin>>n>>k;vector<ll>a(n+1);ll x=n,y=1;ll s=0;while(++s){if(s%2==1){for(ll i=s;i<=n;i+=k){a[i]=x;x--;}}else {for(ll i=s;i<=n;i+=k){a[i]=y;y++;}}if(s==k) break;}for(ll i=1;i<=n;i++) cout<<a[i]<<' ';cout<<'\n';
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);ll t;cin>>t;while(t--) solve();return 0;
}
这篇关于Codeforces Round 923 (Div. 3) A - E的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!