Codeforces Round 923 (Div. 3)

A. Make it White

#include<bits/stdc++.h>
using namespace std;
void solve(){
	int a,b,n;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='B'){
			a=i;
			break;
		}
	}
	for(int i=n-1;i>=0;i--){
		if(s[i]=='B'){
			b=i;
			break;
		}
	}
	cout<<b-a+1<<"\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

B. Following the String 暴力

image
image

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
void solve(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	map<char,int>mp;
	for(int i=1;i<=n;i++){
		int x=a[i];
		for(char j='a';j<='z';j++){
			if(mp[j]==x){
				cout<<j;
				mp[j]++;
				break;
			}
		}
	}
	cout<<"\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

C. Choose the Different Ones! 贪心+思维

image
image

#include<bits/stdc++.h>
using namespace std;
void solve(){
	int n,m,k;
	cin>>n>>m>>k;
	map<int,int>mp1;
	map<int,int>mp2;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(x<=k)mp1[x]++;
	}
	for(int i=1;i<=m;i++){
		int x;
		cin>>x;
		if(x<=k)mp2[x]++;
	}
	int t1=0,t2=0,t3=0;
	for(int i=1;i<=k;i++){
		if(mp1[i]&&!mp2[i])t1++;
		else if(!mp1[i]&&mp2[i])t2++;
		else if(mp1[i]&&mp2[i])t3++;
		else{
			cout<<"NO\n";
			return;
		}
	}
	for(int i=0;i<=t3;i++){
		if(t1+i==t2+(t3-i)&&t1+i==k/2){
			cout<<"YES\n";
			return;
		}
	}
	cout<<"NO\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

D. Find the Different Ones!

image
image
image

有点像dp // a[i]代表了与a[i]不同值的a[j]的最近下表j且j< i

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
int b[N];
void solve(){
	int n;
	cin>>n;
	int c=0;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=2;i<=n;i++){
		if(a[i-1]!=a[i]){
			c=i-1;
		}
		b[i]=c;
	}
	int q;
	cin>>q;
	for(int i=1;i<=q;i++){
		int l,r;
		cin>>l>>r;
		if(b[r]<l){
			cout<<-1<<" "<<-1<<"\n";
		}else{
			cout<<b[r]<<" "<<r<<"\n";
		}
	}
	cout<<"\n";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

本文作者:yufan1102

本文链接:https://www.cnblogs.com/yufan1102/p/18014463

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   yufan1102  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.