Educational Codeforces Round 85 (Rated for Div. 2)
A:
int T, n, a[N], b[N];
int main() {
scanf("%d", &T);
while(T --) {
scanf("%d", &n);
bool tag = 1;
for(int i = 1; i <= n; i ++) {
scanf("%d%d", a + i, b + i);
tag &= a[i] >= b[i];
if(i > 1) {
tag &= a[i] >= a[i - 1];
tag &= b[i] >= b[i - 1];
tag &= a[i] - a[i - 1] >= b[i] - b[i - 1];
}
}
puts(tag ? "YES" : "NO");
}
return 0;
}
B:假设答案为\(k\),肯定是选最富的\(k\)个人均分一下,排序check一下即可。
int T, n, x, a[N];
int main() {
scanf("%d", &T);
while(T --) {
scanf("%d%d", &n, &x);
int res = 0;
for(int i = 1; i <= n; i ++) {
scanf("%d", a + i);
}
sort(a + 1, a + n + 1, greater<int>());
ll sum = 0;
for(int i = 1; i <= n; i ++) {
sum += a[i];
if(sum >= 1ll * x * i) {
res = i;
}
}
printf("%d\n", res);
}
return 0;
}
C:先确定最先打哪个怪\(x\),然后最优打怪方案肯定是\(x,x+1,...,n,1,..,x-1\),断环为链即可。
int T, n;
ll a[N], b[N], sum[N];
int main() {
scanf("%d", &T);
while(T --) {
scanf("%d", &n);
for(int i = 1; i <= n; i ++) {
scanf("%lld%lld", a + i, b + i);
a[i + n] = a[i]; b[i + n] = b[i];
}
for(int i = 1; i <= 2 * n; i ++) {
sum[i] = sum[i - 1] + max(0ll, a[i] - b[i - 1]);
}
ll ans = 2e18;
for(int i = 1; i <= n; i ++) {
ans = min(ans, sum[i + n - 1] - sum[i] + a[i]);
}
printf("%lld\n", ans);
}
return 0;
}
D:自己模拟一下,发现最优路径是:
\(1,2,1,3,..,1,n\);\(2,3,2,4,2,...,2,n\);\(...\);\(1\)。
直接模拟即可。
int T, n, len, seq[N];
ll l, r;
void getseq(int u) {
for(int i = u + 1; i <= n; i ++) {
seq[++ len] = u;
seq[++ len] = i;
}
}
int main() {
scanf("%d", &T);
while(T --) {
scanf("%d%lld%lld", &n, &l, &r);
bool tag = 0;
if(r == n * (n - 1ll) + 1) {
r --; tag = 1;
}
ll sum = 0, pre = 0; len = 0;
for(int i = 1; i <= n; i ++) {
if(r <= sum) break ;
sum += 2 * (n - i);
if(sum >= l) {
getseq(i);
} else {
pre += 2 * (n - i);
}
}
l -= pre; r -= pre;
for(int i = l; i <= r; i ++)
printf("%d ", seq[i]);
if(tag) printf("1 ");
puts("");
}
return 0;
}
E:题意转化就是\(p_1^{c_1}p_2^{c_2}...p_k^{c_k}\),把\(c_p\)加一或减一,代价是\(\prod_{i \not = p}(c_i+1)\)。猜结论:先降再升,降和升的顺序无所谓,就一错排方案。
F:
Educational Codeforces Round 85 (Rated for Div. 2) 简要题解
原文:https://www.cnblogs.com/hongzy/p/12680632.html