A. Prime Subtraction
Description
给两个数$x,y,x \gt y$,判断$x-y$是否为一个素数的整数倍
Solution
由唯一分解可得每个大于1的数都可以唯一分解为素数幂次之积,显然只需要判断x-y是否大于1即可

1 #include <algorithm>
2 #include <cctype>
3 #include <cmath>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cstring>
7 #include <iostream>
8 #include <map>
9 #include <numeric>
10 #include <queue>
11 #include <set>
12 #include <stack>
13 #if __cplusplus >= 201103L
14 #include <unordered_map>
15 #include <unordered_set>
16 #endif
17 #include <vector>
18 #define lson rt << 1, l, mid
19 #define rson rt << 1 | 1, mid + 1, r
20 #define LONG_LONG_MAX 9223372036854775807LL
21 #define pblank putchar(' ')
22 #define ll LL
23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
24 using namespace std;
25 typedef long long ll;
26 typedef long double ld;
27 typedef unsigned long long ull;
28 typedef pair<int, int> P;
29 int n, m, k;
30 const int maxn = 1e5 + 10;
31 template <class T>
32 inline T read()
33 {
34 int f = 1;
35 T ret = 0;
36 char ch = getchar();
37 while (!isdigit(ch))
38 {
39 if (ch == '-')
40 f = -1;
41 ch = getchar();
42 }
43 while (isdigit(ch))
44 {
45 ret = (ret << 1) + (ret << 3) + ch - '0';
46 ch = getchar();
47 }
48 ret *= f;
49 return ret;
50 }
51 template <class T>
52 inline void write(T n)
53 {
54 if (n < 0)
55 {
56 putchar('-');
57 n = -n;
58 }
59 if (n >= 10)
60 {
61 write(n / 10);
62 }
63 putchar(n % 10 + '0');
64 }
65 template <class T>
66 inline void writeln(const T &n)
67 {
68 write(n);
69 puts("");
70 }
71 int main(int argc, char const *argv[])
72 {
73 #ifndef ONLINE_JUDGE
74 freopen("in.txt", "r", stdin);
75 // freopen("out.txt", "w", stdout);
76 #endif
77 int t = read<int>();
78 while (t--)
79 {
80
81 ll x = read<ll>(), y = read<ll>();
82 if (x - y == 1)
83 puts("NO");
84 else
85 puts("YES");
86 }
87
88 return 0;
89 }
B. Kill 'Em All
Description
小明想要消灭一群在x正半轴的怪兽。
给出一个怪兽x坐标序列,导弹作用半径r。
小明每次可以选择一个坐标抛一个炸弹,处于炸弹中心的怪兽直接被消灭,处于炸弹右边的怪兽被推移到x+r的位置,同理左边被推到x-r,x为怪兽坐标。
同样被移到原点或者负半轴也会死亡。
求最少能消灭所有怪兽的炸弹数。
Solution
对于炸弹右边的怪兽,由于右边没有限制,可以被推送到无穷远处,而之后还是需要一颗炸弹来消灭,所以往右推移是不可取的。
那么贪心思路就是从最右开始扔炸弹,知道全部被消灭或者移到非正半轴

1 #include <algorithm>
2 #include <cctype>
3 #include <cmath>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cstring>
7 #include <iostream>
8 #include <map>
9 #include <numeric>
10 #include <queue>
11 #include <set>
12 #include <stack>
13 #if __cplusplus >= 201103L
14 #include <unordered_map>
15 #include <unordered_set>
16 #endif
17 #include <vector>
18 #define lson rt << 1, l, mid
19 #define rson rt << 1 | 1, mid + 1, r
20 #define LONG_LONG_MAX 9223372036854775807LL
21 #define pblank putchar(' ')
22 #define ll LL
23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
24 using namespace std;
25 typedef long long ll;
26 typedef long double ld;
27 typedef unsigned long long ull;
28 typedef pair<int, int> P;
29 int n, m, k;
30 const int maxn = 1e5 + 10;
31 template <class T>
32 inline T read()
33 {
34 int f = 1;
35 T ret = 0;
36 char ch = getchar();
37 while (!isdigit(ch))
38 {
39 if (ch == '-')
40 f = -1;
41 ch = getchar();
42 }
43 while (isdigit(ch))
44 {
45 ret = (ret << 1) + (ret << 3) + ch - '0';
46 ch = getchar();
47 }
48 ret *= f;
49 return ret;
50 }
51 template <class T>
52 inline void write(T n)
53 {
54 if (n < 0)
55 {
56 putchar('-');
57 n = -n;
58 }
59 if (n >= 10)
60 {
61 write(n / 10);
62 }
63 putchar(n % 10 + '0');
64 }
65 template <class T>
66 inline void writeln(const T &n)
67 {
68 write(n);
69 puts("");
70 }
71 vector<ll> vec;
72 int main(int argc, char const *argv[])
73 {
74 #ifndef ONLINE_JUDGE
75 freopen("in.txt", "r", stdin);
76 // freopen("out.txt", "w", stdout);
77 #endif
78 int t = read<int>();
79 while (t--)
80 {
81 n = read<int>();
82 ll r = read<int>();
83 vec.clear();
84 for (int i = 0; i < n; i++)
85 {
86 ll x = read<ll>();
87 vec.emplace_back(x);
88 }
89 sort(vec.begin(), vec.end());
90 auto curend = unique(vec.begin(), vec.end());
91 int sz = (int)(curend - vec.begin());
92 int q = 0;
93 for (int i = sz - 1; i >= 0; i--)
94 {
95 if (vec[i] - q * r <= 0)
96 break;
97 ++q;
98 }
99 writeln(q);
100 }
101 return 0;
102 }
C. Standard Free2play
Description

Solution
找规律可以发现对于连续的一个1状态,如果其长度为奇数,那么这一段1可以无需消耗钻石安稳降落。
而如果长度为偶数,那么它一定得降到最后一个1之上,到最后一个1的时候由于开关触碰,会掉到x-1位置,这时候需要消耗一个钻石保证认为无伤。
模拟即可。注意特判最后一段1序列

1 #include <algorithm>
2 #include <cctype>
3 #include <cmath>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cstring>
7 #include <iostream>
8 #include <map>
9 #include <numeric>
10 #include <queue>
11 #include <set>
12 #include <stack>
13 #if __cplusplus >= 201103L
14 #include <unordered_map>
15 #include <unordered_set>
16 #endif
17 #include <vector>
18 #define lson rt << 1, l, mid
19 #define rson rt << 1 | 1, mid + 1, r
20 #define LONG_LONG_MAX 9223372036854775807LL
21 #define pblank putchar(' ')
22 #define ll LL
23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
24 using namespace std;
25 typedef long long ll;
26 typedef long double ld;
27 typedef unsigned long long ull;
28 typedef pair<int, int> P;
29 int n, m, k;
30 const int maxn = 2e5 + 10;
31 template <class T>
32 inline T read()
33 {
34 int f = 1;
35 T ret = 0;
36 char ch = getchar();
37 while (!isdigit(ch))
38 {
39 if (ch == '-')
40 f = -1;
41 ch = getchar();
42 }
43 while (isdigit(ch))
44 {
45 ret = (ret << 1) + (ret << 3) + ch - '0';
46 ch = getchar();
47 }
48 ret *= f;
49 return ret;
50 }
51 template <class T>
52 inline void write(T n)
53 {
54 if (n < 0)
55 {
56 putchar('-');
57 n = -n;
58 }
59 if (n >= 10)
60 {
61 write(n / 10);
62 }
63 putchar(n % 10 + '0');
64 }
65 template <class T>
66 inline void writeln(const T &n)
67 {
68 write(n);
69 puts("");
70 }
71 unordered_map<int, int> mp;
72 int a[maxn];
73 int main(int argc, char const *argv[])
74 {
75 #ifndef ONLINE_JUDGE
76 freopen("in.txt", "r", stdin);
77 // freopen("out.txt", "w", stdout);
78 #endif
79 int t = read<int>();
80 while (t--)
81 {
82 int h = read<int>();
83 n = read<int>();
84 for (int i = 0; i < n; i++)
85 a[i] = read<int>();
86 int res = 0;
87 int cnt = 1;
88 for (int i = 1; i < n; i++)
89 {
90 if (a[i] == a[i - 1] - 1)
91 ++cnt;
92 else
93 {
94 if (!(cnt & 1))
95 ++res;
96 cnt = 0;
97 }
98 }
99 if (!(cnt & 1) && a[n - 1] > 1)
100 ++res;
101 writeln(res);
102 }
103 return 0;
104 }
D. AB-string
Description

Solution
题解也太妙了8,正着想了好久没想到怎么做。
题解思路,最终good=all-bad
对于bad串,只会出现四种情况。
ABBBBB,BBBBBA
AAAAAB,BAAAAA
那么前后各扫一遍即可,前后可能有长度为2的bad串重复计算,需要减去重复贡献。

1 #include <algorithm>
2 #include <cctype>
3 #include <cmath>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cstring>
7 #include <iostream>
8 #include <map>
9 #include <numeric>
10 #include <queue>
11 #include <set>
12 #include <stack>
13 #if __cplusplus >= 201103L
14 #include <unordered_map>
15 #include <unordered_set>
16 #endif
17 #include <vector>
18 #define lson rt << 1, l, mid
19 #define rson rt << 1 | 1, mid + 1, r
20 #define LONG_LONG_MAX 9223372036854775807LL
21 #define pblank putchar(' ')
22 #define ll LL
23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
24 using namespace std;
25 typedef long long ll;
26 typedef long double ld;
27 typedef unsigned long long ull;
28 typedef pair<int, int> P;
29 int n, m, k;
30 const int maxn = 3e5 + 10;
31 template <class T>
32 inline T read()
33 {
34 int f = 1;
35 T ret = 0;
36 char ch = getchar();
37 while (!isdigit(ch))
38 {
39 if (ch == '-')
40 f = -1;
41 ch = getchar();
42 }
43 while (isdigit(ch))
44 {
45 ret = (ret << 1) + (ret << 3) + ch - '0';
46 ch = getchar();
47 }
48 ret *= f;
49 return ret;
50 }
51 template <class T>
52 inline void write(T n)
53 {
54 if (n < 0)
55 {
56 putchar('-');
57 n = -n;
58 }
59 if (n >= 10)
60 {
61 write(n / 10);
62 }
63 putchar(n % 10 + '0');
64 }
65 template <class T>
66 inline void writeln(const T &n)
67 {
68 write(n);
69 puts("");
70 }
71 char s[maxn];
72 int main(int argc, char const *argv[])
73 {
74 #ifndef ONLINE_JUDGE
75 freopen("in.txt", "r", stdin);
76 // freopen("out.txt", "w", stdout);
77 #endif
78 n = read<int>();
79 scanf("%s", s);
80 ll res = 1LL * (n - 1) * n / 2;
81 int pre = 0;
82 for (int i = 1; i < n; i++)
83 if (s[i] != s[i - 1])
84 res -= i - pre - 1, pre = i;
85 pre = n - 1;
86 for (int i = n - 2; i >= 0; i--)
87 if (s[i] != s[i + 1])
88 {
89 res -= pre - i;
90 pre = i;
91 }
92 writeln(res);
93 return 0;
94 }
