【比赛链接】
【题解链接】
**【A】**King Escape
【思路要点】
- 皇后会攻击到 8 8 8 条直线,其中 4 4 4 条斜向的可以跨过,因此可以忽略。
- 判断起始点和目标点是否在其余 4 4 4 条线分割出的同一个联通块内即可。
- 时间复杂度 O ( 1 ) O(1) O(1) 。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } template <typename T> void write(T x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } template <typename T> void writeln(T x) { write(x); puts(""); } int n, ax, ay, bx, by, cx, cy; int f(int x, int y) { int ans = 0; ans += x < ax; ans *= 2; ans += y < ay; return ans; } int main() { read(n); read(ax), read(ay); read(bx), read(by); read(cx), read(cy); if (f(bx, by) == f(cx ,cy)) printf("YES\n"); else printf("NO\n"); return 0; }
**【B】**Square Difference
【思路要点】
- 由题,我们要判断 a 2 − b 2 a^2-b^2 a2−b2 是否是质数。
- 由于 a 2 − b 2 = ( a + b ) ( a − b ) a^2-b^2=(a+b)(a-b) a2−b2=(a+b)(a−b) ,若 a − b > 1 a-b>1 a−b>1 , a 2 − b 2 a^2-b^2 a2−b2 显然不是质数。
- 否则则判断 a + b a+b a+b 是否为质数即可。
- 时间复杂度 O ( a + b ) O(\sqrt{a+b}) O(a+b) 。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } template <typename T> void write(T x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } template <typename T> void writeln(T x) { write(x); puts(""); } bool prime(ll x) { for (int i = 2; 1ll * i * i <= x; i++) if (x % i == 0) return false; return true; } int main() { int T; read(T); while (T--) { ll a, b; read(a), read(b); if (a == b + 1 && prime(a + b)) printf("YES\n"); else printf("NO\n"); } return 0; }
**【C】**Permutation Game
【思路要点】
- 按照权值从大到小暴力博弈 d p dp dp 即可。
- 时间复杂度 O ( N L o g N ) O(NLogN) O(NLogN) 。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } template <typename T> void write(T x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } template <typename T> void writeln(T x) { write(x); puts(""); } int n, a[MAXN], p[MAXN]; bool dp[MAXN]; bool cmp(int x, int y) { return a[x] > a[y]; } int main() { read(n); for (int i = 1; i <= n; i++) read(a[i]), p[i] = i; sort(p + 1, p + n + 1, cmp); for (int i = 1; i <= n; i++) { int pos = p[i]; for (int j = pos + a[pos]; j <= n; j += a[pos]) if (a[j] > a[pos]) dp[pos] |= !dp[j]; for (int j = pos - a[pos]; j >= 1; j -= a[pos]) if (a[j] > a[pos]) dp[pos] |= !dp[j]; } for (int i = 1; i <= n; i++) if (dp[i]) putchar('A'