Codeforces Round 923 - A.B.C.D

A. Make it White

#include<bits/stdc++.h>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	string s; 
	cin >> s;
	int flag = 0;
	int x = 0, y = -1;
	for (int i = 0; i < n; i++)
	{
		if (flag == 0 && s[i] == 'B')
		{
			flag = 1;
			x = i;
		}
		if (s[i] == 'B')
			y = i;
	}
	cout << y - x + 1 << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

B. Following the String

#include<bits/stdc++.h>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	int a[n + 1];
	for(int i = 1; i <= n; i ++ ) cin >> a[i];
	int m[26] = {0};
	for(int i = 1; i <= n; i ++ )
	{
		for(int j = 0; j < 26; j ++ )
		{
			if(m[j] == a[i])
			{
				m[j] ++ ;
				char c = j + 'a';
				cout << c;
				break;
			}
		}
	}
	cout << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while (T--) solve();
	return 0;
}

C.Choose the Different Ones!

#include<bits/stdc++.h>

using namespace std;

void solve()
{
	int n1, n2, k;
	cin >> n1 >> n2 >> k;
	int a1[n1], a2[n2];
	int b[k+1] = {0};
	for(int i = 0; i < n1; i ++ )
	{
		cin >> a1[i];
		if(a1[i] <= k) b[a1[i]] = 1;
	}
	for(int i = 0; i < n2; i ++ )
	{
		cin >> a2[i];
		if(a2[i] <= k && b[a2[i]] == 1) b[a2[i]] = 3;
		else if(a2[i] <= k && b[a2[i]] != 1 && b[a2[i]] != 3) b[a2[i]] = 2;
	}
	int s1 = 0, s2 = 0, s3 = 0;
	for(int i = 1; i <= k; i ++ )
	{
		if(b[i] == 1) s1 ++ ;
		else if(b[i] == 2) s2 ++ ;
		else if(b[i] == 3) s3 ++ ;
	}
	if(s1 + s2 + s3 != k) cout << "NO" <<endl;
	else
	{
		if(s1 <= k/2 && s1 + s3 >= k/2) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while (T--) solve();
	return 0;
}

D. Find the Different Ones!

#include<bits/stdc++.h>

using namespace std;

void solve()
{
	int n;  
	cin >> n;  
	vector<int> a(n + 1), s(n + 1), nxt(n + 1, -1);
	for(int i = 1; i <= n; i ++) cin >> a[i];
	int i = 1;
	while(i <= n)
	{
		int j = i;
		while(j + 1 <= n && a[i] == a[j + 1]) j ++;
		for(int k = i; k <= j; k ++) nxt[k] = j + 1;
		i = j + 1;
	}
	int q;  
	cin >> q;
	while(q --)
	{
		int l, r;  
		cin >> l >> r;
		if(nxt[l] <= r) cout << l << " " << nxt[l] << "\n";
		else cout << "-1 -1\n";
	}
	cout << "\n";  
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while (T--) solve();
	return 0;
}

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
根据提供的引用内容,Codeforces Round 511 (Div. 1)是一个比赛的名称。然而,引用内容中没有提供与这个比赛相关的具体信息或问题。因此,我无法回答关于Codeforces Round 511 (Div. 1)的问题。如果您有关于这个比赛的具体问题,请提供更多的信息,我将尽力回答。 #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces Round 867 (Div. 3)(A题到E题)](https://blog.csdn.net/wdgkd/article/details/130370975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值