标签:second ber false eof ems 上线 make sort names
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int cnt[26];
char s[1005];
int main() {
IO;
for (cin >> _; _; --_) {
cin >> n;
memset(cnt, 0, sizeof cnt);
rep (i, 1, n) {
cin >> s;
for (int i = 0; s[i]; ++i)
++cnt[s[i] - ‘a‘];
}
bool f = 1;
rep (i, 0, 25) if (cnt[i] % n) { f = 0; break; }
if (f) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
首先发现这题的费用, 要么单调递增, 要么先减后增
且我们有个答案上线, 即 c = 1, $ ans_max = \sum_i (a[i] - 1)$
所以我们直接遍历 c 即可, 只要费用小于当前费用, 就一直搜, 大于当前费用就bereak, 复杂度是够得
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int a[N];
int main() {
IO; cin >> n; ll ans = 0;
rep (i, 0, n - 1) cin >> a[i], ans += a[i] - 1;
sort(a, a + n);
for (int i = 2; ; ++i) {
ll res = 0, cur = 1;
rep (j, 0, n - 1) {
res += abs(a[j] - cur);
if (res >= ans) break;
cur *= i;
}
if (res >= ans) break;
ans = res;
}
cout << ans << ‘\n‘;
return 0;
}
6行, 代表三次就能算出答案
对 2 n, len = n - 1, 将 期间的数变成 n 的倍数
对 1 1, 将 a[1] 变成 len 的倍数
左后 1 n, 都是 n 的倍数 直接 -a[i], 即可
ps 要是n == 1, 更好想
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
ll a[N];
int main() {
IO; cin >> n >> a[1];
cout << "1 1\n" << n - (a[1] % n) << ‘\n‘;
a[1] += n - (a[1] % n);
if (n > 1) cout << "2 " << n << ‘\n‘;
rep (i, 2, n) {
cin >> a[i]; ll res = a[i] % n * (n - 1);
cout << res << ‘ ‘;
a[i] += res;
}
if (n > 1) cout << ‘\n‘;
cout << "1 " << n << ‘\n‘;
rep (i, 1, n) cout << -a[i] << ‘ ‘;
if (n == 1) cout << "\n1 1\n0";
return 0;
}
存在一堆石子的数量大于其他堆的和, 那么先手占住 必胜
否则终将转化为 每堆 都是 1, 直接判奇偶性
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int main() {
IO;
for (cin >> _; _; --_) {
cin >> n; int s = 0, mx = 0;
rep (i, 1, n) cin >> m, s += m, mx = max(mx, m);
if (mx > s - mx || (s & 1)) cout << "T\n";
else cout << "HL\n";
}
return 0;
}
Codeforces Round #666 (Div. 2)
标签:second ber false eof ems 上线 make sort names
原文地址:https://www.cnblogs.com/2aptx4869/p/13587804.html