Codeforces round #666 Div.2
A. Juggling Letters(签到题)
题意:可以随意更换每个字符串中的字母,问能否使所有字符串相同。
题记:求每个字母的个数余n是否都为0即可。
#include<iostream>
#include<queue>
#include<cmath>
#include<cstring>
using namespace std;
#define F first
#define S second
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int dis[][2] = { {0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1} };
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
int t[200];
int main()
{
int T;
cin >> T;
while (T--) {
memset(t, 0, sizeof(t));
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
for (auto x : s) t[x-'A']++;
}
bool flag = true;
//for (int i = 0; i < 26; i++) cout << t[i] << ' ';
//cout << endl;
for (int i = 0; i < 200; i++) {
if (t[i] % n) {
flag = false;
break;
}
}
if (flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
B. Power Sequence(枚举)
题意:给一个数组,求出一个整数c,使得a[i]=ci。问最小花费。
题记:把c从0开始枚举,判断一下花费即可。需要注意如果当前花费已经超过ans了就break。(要不然会)
#include<iostream>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define F first
#define S second
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int dis[][2] = { {0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1} };
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
int n;
ll a[N];
int main()
{
cin >> n;
ll ans = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
ans += a[i];
}
sort(a + 1, a + 1 + n);
for (int i = 0; i < 1000000; i++) {
ll res = 0;
ll k = 1;
for (int j = 1; j <= n; j++) {
if (k > a[j])res += k - a[j];
else res += a[j] - k;
k *= i;
if (res >= ans) break;
}
if (res < ans)ans = res;
}
//cout << r << endl;
cout << ans << endl;
return 0;
}
C. Multiples of Length
题意:有一个数组,每次可以取一个长度为len的区间,区间内的数都可以加上len的长度,使得最后数组所有数都为0。
题记:先将第一个数变成0(取区间为[1,1]),然后取区间[2,n],将每一个a[i]都加上一个a[i]*(n-1)。这样数组的每一个元素都是a[i]*n。都是n的倍数。最后选区间[1,n],将所有数都减去自己即可。
#include<iostream>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define F first
#define S second
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int dis[][2] = { {0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1} };
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
ll a[N];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)cin >> a[i];
if (n == 1) cout << "1 1" << endl << -a[1] << endl<<"1 1"<<endl<<"0"<<endl<<"1 1"<<endl<<"0";
else {
cout << "1 1" << endl << -a[1] << endl << "2 " << n << endl;
a[1] = 0;
for (int i = 2; i <= n; i++) {
cout << a[i] * (n - 1) << " ";
a[i] = a[i] * n;
}
cout << endl<<"1 "<<n<<endl;
for (int i = 1; i <= n; i++) {
cout << -a[i] << " ";
}
cout << endl;
}
return 0;
}
D. Stoned Game(博弈论)
题意:每轮选一个非空且不是上一回合对手选过的一堆石头中拿出一个石头。谁最后不能选了则输。
题记:当有一堆石头数量比其他所有堆得石头都多时,T必赢。否则判断所有石头总数的奇偶性即可。
#include<iostream>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define F first
#define S second
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int dis[][2] = { {0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1} };
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
int main()
{
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
int mmax = 0, sum = 0,x;
for (int i = 1; i <= n; i++) {
cin >> x;
sum += x;
mmax = max(x, mmax);
}
if (mmax > sum - mmax || (sum & 1))cout << "T" << endl;
else cout << "HL" << endl;
}
return 0;
}