小志志和小峰峰的日常(SG函数)
小志志和小峰峰的日常
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
小志志和小峰峰特別喜歡一起討論一些很好玩的問(wèn)題。
小志志發(fā)現(xiàn)一個(gè)有趣的游戲,馬上和小峰峰進(jìn)行了分享。
有 n 堆石子堆,每堆石子個(gè)數(shù)為 a[i]。
到小志志的回合:小志志可以選取其中的一堆,拿至少 1 個(gè)最多 x 個(gè)石子。
到小峰峰的回合:小峰峰可以選取其中的一堆,拿至少 1 個(gè)最多 y 個(gè)石子。
小志志先手,回合交替進(jìn)行,到該玩家回合如果無(wú)法操作,該玩家輸。
Input
輸入一個(gè) T,總共有 T 組測(cè)試數(shù)據(jù)。
每組測(cè)試數(shù)據(jù):
第一行輸入 n 代表有 n 堆石子堆。
第二行輸入 n 堆石子堆分別的數(shù)量。
第三行輸入兩個(gè)用空格隔開(kāi)的 x, y 分別代表小志志和小峰峰對(duì)于一堆石子最多能拿的數(shù)量。
(1 <= n <= 1e5, 1 <= a[i], x, y <= 1e9)
Output
小志志贏輸出 “xzz”,小峰峰贏輸出 “xff”,答案不包含 “”。
Sample Input
3
1
3
2 2
2
4 7
4 5
3
3 4 7
8 8
Sample Output
xff
xzz
xff
Nim 博弈
#include<bits/stdc++.h> using namespace std; const int N = 1e5+5; void show(int ans) {if(ans) cout << "xzz" << '\n';else cout << "xff" << '\n'; } int a[N]; int main(void) {int n, x, y, T;cin >> T;while(T--){cin >> n;for(int i = 0; i < n; i++) cin >> a[i];cin >> x >> y;if(x == y){int ans = 0;for(int i = 0; i < n; i++){ans ^= a[i]%(x+1);}show(ans);}else // x!=y{int flag = 0, ans = 0;for(int i = 0; i < n; i++){ans ^= a[i];if(a[i] > min(x, y)){flag++;}}if(!flag) //a[i] <= min(x, y){show(ans);}else //exit a[i] > min(x, y){if(x > y) cout << "xzz" << '\n';else{if(flag > 1) cout << "xff" << '\n';else{int t;for(int i = 0; i < n; i++){if(a[i] > min(x, y)){t = a[i];ans ^= a[i];break;}}if(t - ans <= x && ans <= x) {cout << "xzz" << '\n';}else cout << "xff" << '\n';}}}}}return 0; }總結(jié)
以上是生活随笔為你收集整理的小志志和小峰峰的日常(SG函数)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 跨公司采购转储(很详细)
- 下一篇: 技术团队管理经验总结(持续更新)