Be the Winner HDU-2509【Nim经典博弈】
2017-08-03 14:15
555 查看
题意: n堆苹果,谁取了最后一个苹果谁输。
思路: 经典的博弈题,亦或所有堆数的苹果数量,如果全是1,那么和堆数有关,否则和亦或的结果有关。亦或值不为0,后手赢;亦或值为0,先手赢。 和平时的亦或结果相反,和这题的 要求 最后一个取的输有关, 以前碰到的都是谁取最后一个谁赢。反一下就可以
思路: 经典的博弈题,亦或所有堆数的苹果数量,如果全是1,那么和堆数有关,否则和亦或的结果有关。亦或值不为0,后手赢;亦或值为0,先手赢。 和平时的亦或结果相反,和这题的 要求 最后一个取的输有关, 以前碰到的都是谁取最后一个谁赢。反一下就可以
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[50]; int main(void) { int n; while(cin >> n) { int flag=0; int ans=0; for(int i=1,x; i<=n; i++) { scanf("%d",&x); ans=ans^x; if(x>1) flag=1; } if(flag==0) { if(n%2==0) printf("Yes\n"); else printf("No\n"); } else { if(ans==0) printf("No\n"); else printf("Yes\n"); } } }
相关文章推荐
- HDU 2509 Be The Winner ( Nim 博弈 )
- hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)
- HDU 2509 Be the Winner (Nim博弈)
- hdu 2509 Be the Winner(博弈Nim)
- hdu 2509 Be the Winner(博弈Nim)
- hdu 2509 Be the Winner(博弈Nim)
- HDU(2509) Be the Winner /HDU(1907) John (Nim 博弈)
- HDU 2509 Be the Winner && HDU 1907 John (Nim博弈变形)
- hdu 2509 Be the Winner(博弈)
- HDU 2509 Be the Winner (Anti-Nim)
- HDU 2509 Be the Winner(Anti-Nim)
- hdu 2509 Be the Winner(博弈)
- [博弈]HDU 2509 Be the Winner
- HDU 2509 Be the Winner(取火柴博弈2)
- HDU2509 Be the Winner 博弈
- (step8.2.2)hdu 2509(Be the Winner——简单博弈)
- (step8.2.2)hdu 2509(Be the Winner——简单博弈)
- HDU-2509-Be the Winner,博弈题~~水过~~
- 20140715 「博弈 - Nim(尼姆)博弈」 HDOJ 2509 Be the Winner
- hdu 2509 - Be the Winner(简单博弈)