「Solution」ABC209

赛后总结

其实题目都不算难,但是比赛的时候都只想了一半的正解。考虑也不周全,T3还把数组开小 Re 了一发。
要多见见题目,思维要开阔一点。

A Counting

题意

给出A, B, 求 $[A, B]$ 中整数元素个数。

题解

1
cout << ((b - a + 1 < 0) ? 0 : (b - a + 1));

B Can you buy them all?

题意

给出一堆数,下标为偶数的数的数值均减一,询问总和与x的大小关系。

题解

按题意模拟即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int x, n, sum;

int main () {
cin >> n >> x;
for (int i = 1, y; i <= n; i++) {
cin >> y;
sum += y;
if (i % 2 == 0) sum--;
}
if (sum <= x) {
printf ("Yes\n");
} else printf ("No\n");
return 0;
}

C Not Equal

题意

给出C数列,构造A数列,满足A中元素互不相同,且a[i] <= c[i]

A数列的个数。

题解

针对于每个a[i],若不考虑相同元素,有a[i]种选择,考虑相同元素,即只有a[i] - k种选择,k是比c[i]小的元素个数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <map>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int Mod = 1e9 + 7;
const int MAXN = 2e5 + 5;

int n, c[MAXN];
long long ans;

int main () {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
ans = 1;
sort (c + 1, c + 1 + n);
for (int i = 1; i <= n; i++) {
ans = (ans % Mod * (c[i] - i + 1) % Mod) % Mod;
}
cout << (ans % Mod) << endl;
return 0;
}

D Collision

题意

两个人在树上走,询问距离是奇数是偶数。

题解

lca板题。


The End
「Ô mon âme, n'aspire pas à la vie immortelle, mais épuise le champ du possible.」