Codeforces Round 923 (Div. 3) 1

problem make it white
describe
给定一串长度为 n 的字符串 s,
s 中只包含 B 和 W ,你可以选择它的一段子串,将该子串内的所有元素染成 W 。要使该字符串全部染成 W ,求选择的子串的最小长度。

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    int n;
    std::cin >> n;
    
    std::string s;
    std::cin >> s;
    
    int l = 0, r = n - 1;
    while (s[l] == 'W') {
        l++;
    }
    while (s[r] == 'W') {
        r--;
    }
    int ans = r - l + 1;
    std::cout << ans << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t;
    std::cin >> t;
    
    while (t--) {
        solve();
    }
    
    return 0;
}

problem following the string
describe
给定一个长度为 n 个序列 a,构造一个长度为n 的字符串 s,si 只能是小写字母 a∼z。ai 表示 s1~si-1 中与si相同的数量。如果有多个 s,输出其中一个即可。

#include<bits/stdc++.h>
using namespace std;
int t;
int n;
int x[200010];
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		int tt[27]={0};
		cin>>n;
		for(register int i=1;i<=n;i++) cin>>x[i];
		for(register int i=1;i<=n;i++)
			for(register int j=0;j<26;j++)
				if(tt[j]==x[i])
				{
					cout<<char(j+'a');
					tt[j]++;
					break;
				}
		printf("\n");
	}
	return 0;
}

problem choose the different ones
describe
给定一个长度为 n 的数组 {a}、一个长度为 m 的数组 {b} 和一个偶数 k,求是否能在 a 和 b 中各选 k/2 个数,使得这些数包括从 1 到 k 的所有整数。

#include<bits/stdc++.h>
#define int long long
using namespace std;
 
bool a[1000005], b[1000005];
 
signed main()
{
	int t;
	cin >> t;
	while(t--){
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		int n, m, k;
		cin >> n >> m >> k;
		for(int i = 1; i <= n; i++){
			int ai;
			cin >> ai;
			a[ai] = true;
		}
		for(int i = 1; i <= m; i++){
			int bi;
			cin >> bi;
			b[bi] = true;
		}
		int acnt = 0, bcnt = 0, cnt = 0;
		bool if_s = false;
		for(int i = 1; i <= k; i++){
			if(a[i] == true && b[i] == false){
				acnt++;
			}
			if(a[i] == true && b[i] == true){
				cnt++;
			}
			if(a[i] == false && b[i] == true){
				bcnt++;
			}
			if(a[i] == false && b[i] == false){
				cout << "No" << endl;
				if_s = true;
				break;
			}
		}
		if(if_s){
			continue;
		}
		if(acnt <= (k / 2) && bcnt <= (k / 2)){
			if(( + bcnt + cnt) <= k){
				cout << "Yes" << endl;
				continue;
			}
		}
		cout << "No" << endl;
	}
	return 0;
}

problem find the different ones
describe

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值