Codeforces Round #696 (Div. 2) Solved: 3 out of 6

Codeforces Round #696 (Div. 2)


A. Puzzle From the Future

题意: 已知一串长度为 n n n并且只由 01 01 01组成的数,要求构造一串长度相同同样由 01 01 01构成的的数字,使得两数相加的和最大,并且相邻两位数不能相同。

#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define _for(i,a,n) for (int i = (a); i <  (n); ++i)

int _T, n;
string a;
void run () {
	cin >> n >> a;
	string b = "1";
	_for (i, 1, n) {
		if ('1' + a[i] != b[i - 1] + a[i - 1]) b += '1';
		else b += '0';
	}
	cout << b << endl;
}

int main () {
	cin >> _T;
	while (_T--) run();
	return 0;
}

B. Different Divisors

题意: 给定一个中间数 d d d,求一个只拥有四个因数的最小值,并且四个因数两两之间的差不能小于 d d d

题解: 因为要找一个只拥有四个因数的某个值,很容易想到去找四个质数求乘积。其实还有可能是这样的组成{ 1 , q , q 2 , q 3 1,q,q^2,q^3 1,q,q2,q3}。最后的答案就从这两种方案里寻最小值即可

#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define pb push_back

void run () {
	int d; cin >> d;
	vector<int>ans;
	for (int i = d + 1; ; ++i) {
		bool flag = true;
		for (int j = 2; j * j <= i; ++j) {
			if (i % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			ans.pb(i);
			break;
		}
	}
	for (int i = ans.back() + d; ; ++i) {
		bool flag = true;
		for (int j = 2; j * j <= i; ++j) {
			if (i % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			ans.pb(i);
			break;
		}
	}
	cout << min(1ll * ans[0] * ans[1], 1ll * ans[0] * ans[0] * ans[0]) << endl;
}

int main () {
	int _T; cin >> _T;
	while (_T--) run();
	return 0;
}

C. Array Destruction

题意: 有一些数字,最初选定两个值获得上界 a i + a j = x a_i + a_j = x ai+aj=x,每次根据上界找到符合 a i + a j = x a_i + a_j = x ai+aj=x的两个数并删除,然后上界变为这连个数的最大值 x = m a x ( a i , a j ) x = max(a_i, a_j) x=max(ai,aj)。问最后能否只留下一个数字。

题解:

#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define pb push_back
#define _for(i,a,n) for (int i = (a); i <  (n); ++i)

typedef long long ll;
const int inf = 0x3f3f3f3f;

vector<int> check (int n, vector<int> tem, int x) {
	vector<int> res;
	multiset<int> a;
	for (auto u : tem) a.insert(u);
	_for (i, 0, n) {
		auto it1 = a.end();
		it1--;
		int y = x - *it1;
		a.erase(it1);
		auto it2 = a.find(y);
		if (it2 == a.end())	return {};
		res.pb(x - y);
		res.pb(y);
		x = max(x - y, y);
		a.erase(it2);		
	}
	return res;	
}
	
void run () {
	int n; cin >> n;
	vector<int> a(2 * n);
	_for (i, 0, 2 * n) cin >> a[i];
	sort(a.begin(), a.end());
	_for (i, 0, 2 * n - 1) {
		int x = a[i] + a[2 * n - 1];
		vector<int> res = check(n, a, x);
		if (res.size()) {
			printf("YES\n%d\n", x);
			_for (j, 0, n) printf("%d %d\n", res[2 * j], res[2 * j + 1]);
			return;
		}
	}
	printf("NO\n");
}

int main () {
	int _T; cin >> _T;
	while (_T--) run();
	return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值