1 条题解
-
0
C++ :
#include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef long long int64; int n, k; int t; int A2[1111], A10[1111]; int64 A30[1111]; bool q[1111]; void initi() { // k = 2 int t; q[0] = t = 0; for (int i = 1; i <= 1024; i++) { q[i] = q[i / 2] ^ (i % 2); if (q[i]) { //cout << "debug A2 " << i << endl; A2[++t] = i; } } // k = 10 for (int i = 0; i <= 10; i++) A10[i] = 1 << i; A10[11] = (1 << 11) - 1; for (int i = 12; i <= 16; i++) A10[i] = 1 << (i - 1); A10[17] = (1 << 16) - (1 << 11) + (1 << 6) - 1; for (int i = 18; i <= 19; i++) A10[i] = 1 << (i - 2); // COR for (int i = 20; i >= 1; i--) A10[i] = A10[i - 1]; //for (int i = 0; i <= 19; i++) cout << "debug A10 " << A10[i] << endl; // k = 30 for (int i = 0; i <= 30; i++) A30[i] = 1 << i; A30[31] = (int64(1) << 31) - 1; for (int i = 32; i <= 46; i++) A30[i] = int64(1) << (i - 1); A30[47] = (int64(1) << 46) - (int64(1) << 31) + (1 << 16) - 1; for (int i = 48; i <= 54; i++) A30[i] = int64(1) << (i - 2); // COR for (int i = 55; i >= 1; i--) A30[i] = A30[i - 1]; //for (int i = 0; i <= 54; i++) cout << "debug A30 " << A30[i] << endl; } void work1(int n) { int x, y = 0; for (int i = 1; i <= n; i++) { cin >> x; y ^= x; } if (y == 0) cout << "Leapfrog.\n"; else cout << "Preempt.\n"; } int calc(int64 x, int p) { for (int i = 1; i <= 100; i++) { if (x % p == p - 1) return i; x /= p; } return 0; } void work2(int n) { int64 x, y = 0; for (int i = 1; i <= n; i++) { cin >> x; y ^= A2[calc(x, 3)]; } if (y == 0) cout << "Leapfrog.\n"; else cout << "Preempt.\n"; } void work10(int n) { int64 x, y = 0; for (int i = 1; i <= n; i++) { cin >> x; y ^= A10[calc(x, 11)]; } if (y == 0) cout << "Leapfrog.\n"; else cout << "Preempt.\n"; } char s[1000]; int a[111], b[111]; int divi(int x) { memset(b, 0, sizeof(0)); int r = 0; for (int i = 100; i >= 0; i--) { b[i] = (a[i] + r) / x; r = ((a[i] + r) % x) * 10; } memcpy(a, b, sizeof(a)); return r / 10; } int calcX() { for (int i = 1; i <= 100; i++) { if (divi(31) == 30) return i; } return 0; } void work30(int n) { int64 y = 0; for (int i = 1; i <= n; i++) { memset(a, 0, sizeof(a)); scanf("%s", s); for (int j = strlen(s) - 1, l = 0; j >= 0; j--, l++) a[l] = s[j] - '0'; y ^= A30[calcX()]; } if (y == 0) cout << "Leapfrog.\n"; else cout << "Preempt.\n"; } int main() { // freopen("game.in", "r", stdin); // freopen("game.out", "w", stdout); initi(); scanf("%d", &t); while (t--) { scanf("%d%d", &n, &k); if (k == 1) work1(n); if (k == 2) work2(n); if (k == 10) work10(n); if (k == 30) work30(n); } return 0; }
- 1
信息
- ID
- 965
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者