Be the Winner HDU-2509【Nim经典博弈】
来源:互联网 发布:淘宝卖家中心进不去 编辑:程序博客网 时间:2024/05/17 01:31
题意: n堆苹果,谁取了最后一个苹果谁输。
思路: 经典的博弈题,亦或所有堆数的苹果数量,如果全是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"); } }}
阅读全文
0 0
- Be the Winner HDU-2509【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(博弈Nim)
- HDU 2509 Be the Winner Nim博弈
- HDU(2509) Be the Winner /HDU(1907) John (Nim 博弈)
- HDU 2509 Be the Winner (Anti-Nim)
- HDU 2509 Be the Winner && HDU 1907 John (Nim博弈变形)
- hdu 2509 Be the Winner(博弈)
- hdu 2509 - Be the Winner(简单博弈)
- [博弈]HDU 2509 Be the Winner
- hdu 2509 Be the Winner(博弈)
- hdu 2509 Be the Winner(博弈Nim)
- hdoj Be the Winner 2509 (NIM博弈)
- HDU2509 Be the Winner Nim博弈
- hdu 1907 John,hdu 2509 Be the Winner anti-NIM
- JavaScript-DOM(document object model)
- Redis 3.0集群原理
- android ipc跨进程通许
- 哈希算法简介
- 在腾讯云中配置ubuntu系统 VPN
- Be the Winner HDU-2509【Nim经典博弈】
- Xdebug安装配置
- 20170803工作记账流水(2017-08-03 10:00)
- H5 学习之 拖动事件
- 【CSS 基础】10 float
- Sublime Text 3如何快速生成HTML5的头部信息和常用的快捷键
- 【DL--15】运行一个TensorFlow
- 1、quartz基本概念
- python 深复制和浅复制