很简单的一场,暴力又白给。值得一提的是这场题目背景居然是CytusII
A:
一开始还想用golang写的,后来发现不会golang的数据结构,于是老老实实滚回c++了。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int t, n, s, k; 21 set<int>a; 22 23 int main() { 24 scanf("%d", &t); 25 while (t--) { 26 a.clear(); 27 scanf("%d%d%d", &n, &s, &k); 28 for (int i = 1; i <= k; i++) { 29 int x; scanf("%d", &x); 30 a.insert(x); 31 } 32 int ans = 0; 33 while (1) { 34 if (s + ans <= n && !a.count(s + ans)) break; 35 if (s - ans > 0 && !a.count(s - ans)) break; 36 ans++; 37 } 38 printf("%d ", ans); 39 } 40 return 0; 41 }
B:
显然每次淘汰一个人能赚到的最多。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int n; 21 22 int main() { 23 scanf("%d", &n); 24 double ans = 0; 25 for (int i = 1; i <= n; i++) ans += 1.0 / (double)i; 26 printf("%.6f ", ans); 27 return 0; 28 }
C:
每次加点删点维护一下建了或摧毁了多少堵“墙”就行。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 1e5 + 10; 21 int a[2][maxn], n, q, wall = 0; 22 23 void solve(int x, int y) { 24 if (a[x][y]) { 25 if (a[x ^ 1][y - 1]) wall--; 26 if (a[x ^ 1][y]) wall--; 27 if (a[x ^ 1][y + 1]) wall--; 28 } else { 29 if (a[x ^ 1][y - 1]) wall++; 30 if (a[x ^ 1][y]) wall++; 31 if (a[x ^ 1][y + 1]) wall++; 32 } 33 a[x][y] = a[x][y] ^ 1; 34 } 35 36 int main() { 37 scanf("%d%d", &n, &q); 38 for (int i = 0; i <= n; i++) a[0][i] = a[1][i] = 0; 39 while (q--) { 40 int x, y; scanf("%d%d", &x, &y); 41 x--; 42 solve(x, y); 43 if (!wall) puts("Yes"); 44 else puts("No"); 45 } 46 return 0; 47 }
D:
很无聊的爆搜。
1 #include <bits/stdc++.h> 2 #define ll long long 3 4 using namespace std; 5 6 const ll inf = 1e17; 7 ll x[105], y[105]; 8 ll ax, ay, bx, by, a, b, t; 9 int n, ans = 0; 10 11 int main(void) { 12 ios_base::sync_with_stdio(0); 13 cin.tie(NULL); 14 cin >> x[0] >> y[0] >> ax >> ay >> bx >> by; 15 // 跑到直到爆边界 16 while (x[n] < inf && y[n] < inf) { 17 ++n; 18 // 不符合要求 19 if (x[n - 1] > (inf - bx) / ax + 1 || y[n - 1] > (inf - by) / ay + 1) { 20 --n; 21 break; 22 } 23 x[n] = ax * x[n - 1] + bx; 24 y[n] = ay * y[n - 1] + by; 25 } 26 cin >> a >> b >> t; 27 // 枚举每个点 28 for (int i = 0; i <= n; ++i) { 29 ll currDis = abs(x[i] - a) + abs(y[i] - b); 30 if (currDis > t) continue; 31 ll remainLen = t - currDis; 32 // O(n^2)枚举前面的两点 33 for (int l = 0; l <= i; ++l) { 34 for (int r = i; r <= n; ++r) { 35 currDis = abs(x[i] - x[l]) + abs(y[i] - y[l]); 36 currDis = min(currDis, abs(x[i] - x[r]) + abs(y[i] - y[r])); 37 currDis += abs(x[l] - x[r]) + abs(y[l] - y[r]); 38 // 剩下的长度能走完则符合要求 39 if (currDis <= remainLen) ans = max(ans, r - l + 1); 40 } 41 } 42 } 43 cout << ans << endl; 44 return 0; 45 }
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 ll xZero, yZero, ax, ay, bx, by, sx, sy, t; 21 22 ll getDis(ll x0, ll y0, ll x1, ll y1) { 23 return abs(x0 - x1) + abs(y0 - y1); 24 } 25 26 int main() { 27 scanf("%lld%lld%lld%lld%lld%lld", &xZero, &yZero, &ax, &ay, &bx, &by); 28 scanf("%lld%lld%lld", &sx, &sy, &t); 29 ll xi = xZero, yi = yZero, xj, yj, xp = xZero, yp = yZero, i = 0, j = 0, p = 0, ans = 0; 30 ll currDis = getDis(xi, yi, sx, sy), lastDis = currDis + 1; 31 while (currDis > t && lastDis > currDis) { 32 xi = xi * ax + bx, yi = yi * ay + by, i++, lastDis = currDis; 33 // calculate distance of each point to start point 34 currDis = getDis(xi, yi, sx, sy); 35 while (currDis + getDis(xi, yi, xp, yp) > t && p <= i) { 36 xp = xp * ax + bx, yp = yp * ay + by, p++; 37 } 38 } 39 j = i; xj = xi; yj = yi; 40 while (currDis <= t) { 41 while (currDis + getDis(xi, yi, xj, yj) <= t) { 42 xj = xj * ax + bx, yj = yj * ay + by, j++; 43 } 44 ans = max(ans, j - i); 45 while (currDis + getDis(xi, yi, xp, yp) > t) { 46 xp = xp * ax + bx, yp = yp * ay + by, p++; 47 } 48 ans = max(ans, i - p + 1); 49 xi = xi * ax + bx, yi = yi * ay + by, i++; 50 currDis = getDis(xi, yi, sx, sy); 51 } 52 printf("%lld ", ans); 53 54 }