Codeforces Round 906 (Div. 2)

A

构造题

#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int maxn = 2e5+5;
 
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
 
inline void solve() {
	int n; cin >> n;
	vector<int>a(n);
 
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int cnt1 = a[0], cnt2 = a[n-1];
	int fg1 = 0, fg2 = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] != cnt1 && a[i] != cnt2) {
			cout << "No\n";
			return;
		}
		else if (a[i] == cnt1) {
			fg1++;
		}
		else
			fg2++;
	}
	if (fg1 == 0 || fg2 == 0) {
		cout << "Yes" << '\n';
	}
	else if (abs(fg1 - fg2) == 1 || abs(fg1 - fg2) == 0) {
		cout << "Yes" << '\n';
	}
	else
		cout << "No\n";
}
 
signed main(){
 
	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);
 
	int t = 1;
	cin >> t;
	while (t--)
		solve();
 
	return 0;
}

B

模拟

#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int maxn = 2e5+5;
 
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
 
inline void solve() {
	int n, m; cin >> n >> m;
	string s1, s2; cin >> s1 >> s2;
	bool fg1 = 0, fg2 = 0;
	for (int i = 1; i < n; i++) {
		if (s1[i] == s1[i - 1]) {
			fg1 = 1;
			break;
		}
	}
	for (int i = 1; i < m; i++) {
		if (s2[i] == s2[i - 1]) {
			fg2 = 1;
			break;
		}
	}
	if (s2[0] != s2[m - 1])
		fg2 = 1;
	if (!fg1) {
		cout << "Yes\n";
		return;
	}
	if ((fg1 && fg2)||(fg1&&m==2)) {
		cout << "No\n";
		return;
	}
 
	bool s1t1 = 0, s1t2 = 0, s2t1 = 0, s2t2 = 0;
	if (s2[0] == s2[m - 1] && s2[0] == '0') {
		s2t1 = 1;
	}
	else
		s2t2 = 1;
 
	for (int i = 1; i < n; i++) {
		if (s1[i] == s1[i - 1]&&s1[i]=='0') {
			s1t1 = 1;
		}
		else if (s1[i] == s1[i - 1] && s1[i] == '1') {
			s1t2 = 1;
		}
	}
	if (s1t1 && s1t2) {
		cout << "No\n";
		return;
	}
	if (s2t1) {
		if (s1t1) {
			cout << "No\n";
			return;
		}
		else {
			cout << "Yes\n";
			return;
		}
	}
	else {
		if (s1t2) {
			cout << "No\n";
			return;
		}
		else {
			cout << "Yes\n";
			return;
		}
	}
}
 
signed main(){
 
	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);
 
	int t = 1;
	cin >> t;
	while (t--)
		solve();
 
	return 0;
}

C

模拟,注意k不能为奇数,字符串里01数量相同,1相同在左边的1前面加01,0相同在右边0的后面加01,注意边界维护

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int maxn = 2e5+5;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve() {
	int k; cin >> k;
	string s; cin >> s;
	string t = "01";
	int cnt0 = count(s.begin(), s.end(), '0');
	int cnt1 = k - cnt0;
	if ((cnt1 != cnt0) || k & 1) {
		cout << "-1\n";
		return;
	}

	vector<int>ans;

	int L = 0, R = k - 1;
	while (L < R) {
		if (s[L] != s[R]) {
			L++, R--;
			continue;
		}
		if (s[L] == '0') {
			ans.push_back(R + 1);
			s.insert(R + 1, t);
			R += 2;
		}
		else {
			ans.push_back(L);
			s.insert(L, t);
			R += 2;
		}
	}

	cout << ans.size() << '\n';
	for (auto i : ans) {
		cout << i << ' ';
	}
	cout << '\n';
}

signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

D

可以推出如果初始时候,存在i和j不为1的点使得ai+aj>=ijc,那么a1一定至少能与其中一点连边

那么我们用升序优先队列来存,只要a1+ai-i*c>=0就可以插到a[i]上,插入后可以把两个点合并为a[1],从ai-i*c最大开始,如果队列空就可以

#include<bits/stdc++.h>
#define int ll
using namespace std;
using ll = long long;
const int maxn = 2e5+5;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve() {
	int n, c; cin >> n >> c;
	vector<int>a(n);
	priority_queue<pair<int, int>>q;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if(i!=0)
			q.push({ a[i] - (i+1) * c,a[i] });
	}

	int t = a[0];
	while (!q.empty() && t + q.top().first >= 0) {
		t += q.top().second;
		q.pop();
	}
	if (q.empty())
		cout << "Yes\n";
	else
		cout << "No\n";
}

signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值