QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#364960 | #6789. Yet Another Game of Stones | Xiangmy | AC ✓ | 66ms | 4004kb | C++20 | 1.9kb | 2024-03-24 17:35:41 | 2024-03-24 17:35:41 |
Judging History
answer
/*
* Author: Xiangmy
* Created: 2024-03-24 16:02
* Problem:
* Description: 博弈 nim游戏
* 如果除A的 1、2 限制外就是普通的nim游戏。于是只剩下4种情况需要特判。
* 1.奇数(1):如果大于1,A先手不取完,B就取完,A输;否则B变为先手。
* 2.奇数(2):A必输
* 3.偶数(1):需要A先手将其取至1,变成B先手的nim游戏。有两个A必输。
* 4.偶数(2):A先手不取完,B就取完,A输;否则B变为先手。
* 2 || (1 && 4) 则必输
*/
// #pragma GCC optimize(2)
// #pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << (x) << ' '
// #define x first
// #define y second
typedef long long LL;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> PII;
void solve() {
int n; cin >> n;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; ++ i) cin >> a[i];
for (int i = 1; i <= n; ++ i) cin >> b[i];
int ans = 0;
int cnt = 0;
bool lose = false;
for (int i = 1; i <= n; ++ i) {
if (a[i] == 1 && b[i] == 1) ans ^= 1;
else if ((a[i] & 1) && b[i] == 1 || !(a[i] & 1) && b[i] == 2) cnt ++;
else if ((a[i] & 1) && b[i] == 2) lose = true;
else if (!(a[i] & 1) && b[i] == 1) {
cnt ++;
ans ^= 1;
}
else ans ^= a[i];
}
if (lose || cnt > 1) cout << "Bob\n";
else if (cnt && ans || !cnt && !ans) cout << "Bob\n";
else cout << "Alice\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); // 交互题不用
cout.tie(0);
// cout << fixed << setprecision(6);
// cout << setw(4) << setfill('0');
// init();
int T = 1;
cin >> T;
while (T -- ) {
// cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
3 2 4 1 1 0 1 3 2 1 1 2
output:
Alice Bob Bob
result:
ok 3 tokens
Test #2:
score: 0
Accepted
time: 66ms
memory: 4004kb
input:
1015 7 2 3 4 1 5 1 4 0 0 0 0 0 1 2 6 6 5 5 6 5 1 0 1 2 2 2 1 4 2 6 2 3 0 0 0 0 3 4 5 5 0 2 2 6 6 1 6 1 4 5 2 1 1 0 2 0 3 4 4 3 0 1 2 5 6 3 5 4 4 1 2 0 1 1 5 6 3 1 1 5 1 2 1 1 2 4 3 4 5 3 0 0 0 2 4 6 1 5 1 2 1 2 2 5 1 4 3 2 6 1 2 0 0 2 4 6 2 1 1 0 0 2 2 1 6 2 3 5 1 4 2 0 0 1 5 0 6 1 6 6 4 5 6 1 2 1 0...
output:
Alice Bob Alice Bob Bob Bob Bob Bob Bob Bob Bob Bob Alice Bob Alice Bob Bob Bob Bob Alice Bob Alice Bob Alice Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Alice Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Alice Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Alice Alice Al...
result:
ok 1015 tokens