A - Xenny and Alternating Tasks
Title Solution
Enumerate who did it on the first day and take the two answers to (min).
Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <cctype> #define gI gi #define itn int #define File(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout) using namespace std; inline int gi() { int f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();} while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();} return f * x; } int t, n, a[20003], b[20003]; int main() { //File("XENTASK"); t = gi(); while (t--) { n = gi(); for (int i = 1; i <= n; i+=1) a[i] = gi(); for (itn i = 1; i <= n; i+=1) b[i] = gi(); itn ans = 0, sum = 0; for (itn j = 1; j <= n; j+=1) { if (j & 1) sum = sum + a[j]; else sum = sum + b[j]; } for (int j = 1; j <= n; j+=1) { if (j & 1) ans = ans + b[j]; else ans = ans + a[j]; } printf("%d\n", min(ans, sum)); } return 0; }
B - Bear and Extra Number
Title Solution
Sort the arrays, traverse the elements of the arrays, and then classify and discuss:
- If \(a_i = a {i+1}), then output (a_i).
- If u (a {i+1}-a_i>1):
- Because there is a unique solution to the title, so (i) can only be (n-1) or (1\).
- If \(i) is (n-1), then output (a_n\).
- If (i) is (1), then output (a_1).
- Because there is a unique solution to the title, so (i) can only be (n-1) or (1\).
Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <cctype> #define gI gi #define itn int #define File(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout) using namespace std; inline int gi() { int f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();} while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();} return f * x; } int t, n, a[100003], ans, sum; int main() { //File("EXTRAN"); t = gi(); while (t--) { n = gi(); for (itn i = 1; i <= n; i+=1) a[i] = gi(); sort(a + 1, a + 1 + n); for (int i = 1; i < n; i+=1) { if (a[i + 1] == a[i]) {printf("%d\n", a[i]); break;} if (a[i + 1] - a[i] > 1) { if (i == n - 1) {printf("%d\n", a[n]); break;} else if (i == 1) {printf("%d\n", a[1]); break;} } } } return 0; }
C - Cooking Schedule
Title Solution
Two points.
The key is how to write (check).
There's no time today. First dig a hole and then fill it tomorrow.