【Codeforces】Codeforces Round 834 (Div. 3) (ABCDE)(补赛)

Yes-Yes?

解题思路

使用stl库找子串

参考代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
const int N = 2e5 + 5;
ll T;
string s = "Yes", ss, x;
void solve() {
	cin >> x;
	if (ss.find(x) != -1) cy;
	else cn;
}
int main() {
	for (int i = 1; i <= 100; i++) ss += s;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	T = 1;
	cin >> T;
	while (T--) solve();
	return 0;
}

Lost Permutation

解题思路

先找出最大的数,把没出现的数减去,再延长排列,最后看s是否符合条件

参考代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
const int N = 2e5 + 5;
ll T;
ll m, s;
ll b[N];
unordered_map<int, bool>mp;
void solve() {
	ll ma = 0;
	mp.clear();
	cin >> m >> s;
	for (int i = 1; i <= m; i++) {
		cin >> b[i];
		ma = max(b[i], ma);
		mp[b[i]] = 1;
	}
	for (int i = 1; i <= ma; i++) {
		if (!mp[i]) s -= i;
	}
	while (s > 0) {
		ma++;
		s -= ma;
	}
	if (s == 0) cy;
	else cn;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	T = 1;
	cin >> T;
	while (T--) solve();
	return 0;
}

Thermostat

解题思路

分类讨论

参考代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
const int N = 2e5 + 5;
ll T;
ll l, r, x, a, b;
void solve() {
	cin >> l >> r >> x >> a >> b;
	ll d = abs(a - b);
	if (a == b) {
		cout << 0 << endl;
		return;
	}
	if (d >= x) {
		cout << 1 << endl;
		return;
	}
	if (a < b) {
		if (r - b >= x || a - x >= l) cout << 2 << endl;
		else if (b - l >= x && a + x <= r)  cout << 3 << endl;
		else cout << -1 << endl;
	} else {
		if (b - l >= x || a + x <= r) cout << 2 << endl;
		else if (r - b >= x && a - x >= l)  cout << 3 << endl;
		else cout << -1 << endl;
	}
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	T = 1;
	cin >> T;
	while (T--) solve();
	return 0;
}

Make It Round

解题思路

10的因子有5和2,记录n因子2和5的个数,那么当cnt2和cnt5相等时,尽可能使0最大

参考代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
const int N = 2e5 + 5;
ll T;
ll n, m;
ll ans;
ll find0(ll x) {
	ll cnt = 0;
	while (x) {
		if (x % 10 == 0) cnt++;
		else break;
		x /= 10;
	}
	return cnt;
}

void solve() {
	ll k = 1;
	cin >> n >> m;
	ll cnt2 = 0, cnt5 = 0;
	ll x = n;
	while (x > 0 && x % 2 == 0) {
		cnt2++;
		x /= 2;
	}
	x = n;
	while (x > 0 && x % 5 == 0) {
		cnt5++;
		x /= 5;
	}
	while (cnt5 < cnt2 && k * 5 <= m) {
		cnt5++;
		k *= 5;
	}
	while (cnt2 < cnt5 && k * 2 <= m) {
		cnt2++;
		k *= 2;
	}
	while (k * 10 <= m) k *= 10;
	if (k == 1) ans = n * m;
	else k *= m / k, ans = n * k;
	cout << ans << endl;

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

The Humanoid

解题思路

考虑贪心,首先肯定从小的开始,那么先把a排序,但是不知道怎么喝药才最优,因为数据量比较小,可以dfs搜索出最优解

参考代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
const int N = 2e5 + 5;
ll T;
ll n, h;
ll a[N];
ll ans;
void dfs(ll k, ll x, int g, int b, ll res) {
	if (res > n) return;
	if (x > a[k]) dfs(k + 1, x + a[k] / 2, g, b, res + 1);
	else {
		if (g > 0) 	dfs(k, 2 * x, g - 1, b, res);
		if (b > 0) 	dfs(k, 3 * x, g, b - 1, res);
	}
	ans = max(ans, res);
}
void solve() {
	ans = 0;
	cin >> n >> h;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	dfs(1, h, 2, 1, 0);
	cout << ans << endl;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	T = 1;
	cin >> T;
	while (T--) solve();
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值