Codeforces Round #666 (Div. 2) 题解报告

https://codeforces.com/contest/1397/problem/A

image-20200831080704501

image-20200831080704501

题意:

给定n个字符串,问重新组合以后是否能构成相同的n个字符串

思路:

直接判断所给的字符串的每种字母是否能被n整除即可。

//稍微写复杂了
#include<bits/stdc++.h>
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
const int N = 1e5 + 100;
ll n, m, a[N], i, j;

void solve() {
	ms(a, 0);
	cin >> n;
	string s; ll cnt = 0;
	for (int i = 0; i < n; ++i) {
		cin >> s; for (int j = 0; j < s.length(); ++j) {
			a[s[j] - 'a']++;
		}
		cnt += s.length();
	}
	if (cnt % n != 0)cout << "NO" << endl;
	else {
		for(int i = 0;i < 26;++i)
			if (a[i] % n != 0) {
				cout << "NO" << endl;
				return;
			}
		cout << "YES" << endl;
	}
}

int main() {
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) solve();
}

https://codeforces.com/contest/1397/problem/B

题意:

利用每次代价都为1的ai+1 or ai1 构建幂序列。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100100], n;
ll ans = 0x3f3f3f3f3f3f3f3f;
int main() {
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n; for (int i = 1; i <= n; ++i)cin >> a[i];
	int lim = pow(1e18, 1.0 / n);
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= lim; i++) {
		ll now = 0, k = 1;
		for (int j = 1; j <= n; ++j) {
			now += abs(k - a[j]);
			k *= i;
		}
		ans = min(ans, now);
	}
	cout << ans << endl;
}

https://codeforces.com/contest/1397/problem/C

没有做出,先贴一下dalao代码

#include<iostream>
using namespace std;
int main(){
	long long n; cin >> n;
	long long a[n + 1];
	for (int i = 1; i <= n; i++)
        cin >> a[i];
	cout << "1 1" << endl << a[1] * (n - 1) << endl;
	(n == 1) ? cout << "1 1" << endl << "0" : cout << "2 " << n << endl;
	for (int i = 2; i <= n; i++)
        cout << a[i] * (n - 1) << " ";
	cout << endl << "1 " << n << endl;
	for (int i = 1; i <= n; i++)
        cout << -a[i] * n << " ";
}

https://codeforces.com/contest/1397/problem/D

image-20200831092359029

image-20200831092359029

题意:

T和HL玩游戏,再给定的石堆中选择一个(但不能是上一个人取的那堆)取一个石子。一旦有一方不能取石头则判输

思路:

博弈问题,先统计所有石头数,如果sum小于mx(最多石头的一堆)的两倍或者sum为奇数则必然是T能赢,不然就是HL赢

#include<bits/stdc++.h>
using namespace std;
int main() {
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		int sum = 0, mx = 0;
		while (n--) {
			int x; cin >> x;
			sum += x;
			if (x > mx)mx = x;
		}
		if (sum - mx < mx || sum % 2 == 1)cout << "T\n";
		else cout << "HL\n";
	}
}
posted @   RioTian  阅读(326)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 全程不用写代码,我用AI程序员写了一个飞机大战
点击右上角即可分享
微信分享提示