【BestCoder Round 65B】【博弈 对称思想】ZYB's Game 范围取数都知道x谁取到x谁必败
来源:互联网 发布:ubuntu 卸载cuda9 编辑:程序博客网 时间:2024/05/22 17:17
ZYB's Game
Accepts: 672
Submissions: 1207
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
问题描述
ZYB在远足中,和同学们玩了一个“数字炸弹”游戏:由主持人心里想一个在[1,N]中的数字X,然后玩家们轮流猜一个数字,如果一个玩家恰好猜中X则算负,否则主持人将告诉全场的人当前的数和X比是偏大还是偏小,然后猜测的范围就会相应减小,一开始的范围是[1,N].每个玩家只能在合法的范围中猜测.现在假设只有两个人在玩这个游戏,并且两个人都已经知道了最后的X,若两个人都采取最优策略.求X∈[1,N]中是后手胜利的X数量.
输入描述
第一行一个整数T表示数据组数。接下来T行,每行一个正整数N.1≤T≤100000,1≤N≤10000000
输出描述
T行每行一个整数表示答案.
输入样例
13
输出样例
1
#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}const int N=0,M=0,Z=1e9+7,ms63=1061109567;int casenum,casei;int n;int main(){scanf("%d",&casenum);for(casei=1;casei<=casenum;++casei){scanf("%d",&n);printf("%d\n",n&1);}return 0;}/*【题意】Alice和Bob做猜数游戏,Alice先手。已知数x是[1,n]中的任意一个,Alice,Bob和裁判都知道是哪一个。每个人猜数的时候,裁判会告诉你,当前猜的数比答案大还是比答案小。于是我们猜的范围只能逐渐减小。两个人都采取最优决策。最后,猜中x的哪个人算输。问你,存在多少个x,使得后手的人必胜。【类型】博弈 对称思想【分析】当n==1,后手在x==1时必胜当n==2,后手必败当n==3,后手在x==2时必胜当n==4,后手必败当n==5,后手在x==3时必胜我们已经发现了——当n为偶数,偶数必败。当n为奇数,后手仅在x==(n+1)/2时必胜。为什么有这个结论呢?我们可以运用博弈比较常见的对称性思想——如果x是最中间的数,先手不论怎么取,我们想,后手只要对称着来就好啦。于是最后一次取数肯定是先手取走了x,所以先手必败。如果x不是最中间的数,那么先手必然可以通过一步取数,使得x变成最中间的数。于是先手必胜。呀,对称性思想真是棒。一下子我们就完成证明了哦。【时间复杂度&&优化】O(1)*/
0 0
- 【BestCoder Round 65B】【博弈 对称思想】ZYB's Game 范围取数都知道x谁取到x谁必败
- BestCoder Round #65 B. ZYB's Game(组合游戏)
- BestCoder Round #65 ZYB's Game
- BestCoder Round #65 ZYB's Game
- BestCoder Round #65 1002 ZYB's Game HDU5591
- BestCoder Round #65 ZYB's Biology
- BestCoder Round #65 ZYB's Premutation
- BestCoder Round #65 D. ZYB's Tree(树形dp)
- BestCoder Round #65 HDOJ5592 ZYB's Premutation(树状数组+二分)
- BestCoder Round #65 1001 ZYB's Biology HDU5590
- HDOJ 5591 ZYB's Game(简单博弈)
- HDU 5591 ZYB's Game(博弈)
- 【博弈】HDOJ ZYB's Game 5591
- HDOJ 5591 ZYB's Game 【简单博弈 】
- HDU5591 - ZYB's Game (简单博弈)
- 【BestCoder Round 65D】【树形DP 容斥思想】ZYB's Tree 求距离每个节点距离不超过k的节点数
- BestCoder #65 1003 ZYB's Premutation
- BestCoder Round #65 C. ZYB's Premutation(线段树求第k大)
- Android studio创建AIDL传递复杂参数
- 【BestCoder Round 65A】【水题】ZYB's Biology DNA与RNA是否匹配
- UI-第一讲:UIKit框架-UIKit-UIView
- android学习笔记11(1)——Fragment学习笔记
- LeetCode263——Ugly Number
- 【BestCoder Round 65B】【博弈 对称思想】ZYB's Game 范围取数都知道x谁取到x谁必败
- JavaScript----this陷阱的最全收集
- iOS清除UIDatePicker和UIPickerView中间Row上面的分割线
- 关于com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536的解决方法
- Ext.js问题重现整理(1)(树和路由)
- 【Zookeeper】基本配置
- oracle 行列转换
- android simple github 官网地址
- angularjs之函数