自己vp了一下这一场,赛时7题,比较简单,但是有几题也是卡了蛮久。
都是思维题。
C
感觉结论比较显然但是实现上被卡住了。
用map没过,重构的时候把多个数压缩成一个数处理ac了,对拍发现是因为循环逻辑导致错误了。。
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define int long long
#define lowbit(x) (x & (-x))
const int N = 2e5 + 10;
int n, ans;
void solve() {cin >> n;map<int, int>mp;for (int i = 1; i <= n; i++) {int x; cin >> x;mp[x]++;}int j = 0;int b[5] = {0, 0, 0, 0, 0}, k = 0;for (auto &i : mp) {// cout << i.first << ' ' << i.second << endl;if (k < 4){while(k + 1 < 5 && i.second >= 2) {i.second -= 2;b[++k] = i.first;}}if (k == 4) {while(i.second >= 2) {i.second -= 2;b[3] = i.first;if (b[3] >= b[4]) swap(b[3], b[4]);}continue;}}if (k < 4) cout << "NO" << endl;else {cout << "YES" << endl;cout << b[1] << ' ' << b[2] << ' ' << b[1] << ' ' << b[4] << ' ';cout << b[3] << ' ' << b[2] << ' ' << b[3] << ' ' << b[4] << endl;}
}
signed main() {int T = 1;cin >> T;while (T--) solve();
}
G
交互题
因为只需要知道一个数,去考虑1后面接的到底是什么数,所以问11,1,10三个,就可以知道1后面到底有没有每个都接着数字
B
之前见过一些类似题所以思路想的比较快
结论1是操作n次可以使全部值-1,也就是说答案具有单调性可以二分
结论2是说暴力check的次数不会超过 log(Amax) 次因为每次可以操作的数都会至少减半
所以可以直接写(在结论2上面卡了很久没搞对)
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define int long long
#define lowbit(x) (x & (-x))
const int N = 2e5 + 10;
int n, ans, k, a[N], idmx, b[N];
LL sum = 0;
bool jud(int mid) {LL op = 1ll * mid * n + k;int avg = (sum - op) / n;LL cnt = 0;for (int i = 1; i <= n; i++) b[i] = a[i];for (int i = 1; ; i++) {if (op == 0) break;int j = ((i - 1) % n) + 1, tmp = (i % n) + 1;if (b[j] > avg) {b[tmp] = b[tmp] + (b[j] - avg + 1) / 2;op -= (b[j] - avg + 1) / 2;b[j] -= (b[j] - avg + 1) / 2 * 2;}if (b[tmp] <= avg && i > n) break;if (op < 0) return 0;}for (int i = 1; i <= n; i++) if (b[i] != avg) return 0;return 1;
}
void solve() {cin >> n;sum = 0;for (int i = 1; i <= n; i++) {cin >> a[i];sum += a[i];}bool f = 1;for (int i = 1; i < n; i++) {if (a[i] != a[i + 1]) {f = 0; break;}}if (f) {cout << 0 << endl;return;}k = sum % n;int l = 0, r = sum / n , mid = (l + r) / 2;while (l < r) {if (jud(mid)) r = mid;else l = mid + 1;mid = (l + r) / 2;}// cout << sum << ' ' << n << << endl;if (jud(mid) == 0) cout << -1 << endl;else cout << 1ll * mid * n + k << endl;
}
signed main() {int T = 1;cin >> T;while (T--) {solve();}
}