zoj3882 Help Bob 博弈
来源:互联网 发布:大屏幕实时数据展示 编辑:程序博客网 时间:2024/05/16 17:41
题意:两个人博弈,地上有n个标号从1~n的石子,然后每人依次拿走一个石头,在拿走一个石头的同时,它的因数石子也会被同时去掉,0<=n<=60。最后石子都被拿光后,没的石子拿的那个人输掉。给你不同的n,让你求先手胜还是负。
解题思路:想明白了很简单,想不通就做不出来。
假设存在一种n并且先手选2~n,是先手必败,那么后手就是必胜了,此时1已经被取走了,因为1是所有数的因数。那么如此来看,先手如果不选2~n,而选1,那么必败态就留给后手了,所以无论如何主动权都是在先手的人,先手可以选择是否先拿走1,所以先手必胜。当然,n=0除外。.
There is a game very popular in ZJU at present, Bob didn't meant to participate in it. But he decided to join it after discovering a lot of pretty girls playing it.
There are n stones on the ground and they are marked as 1 to n respectively. There will be 2 players in each competition. And the game rules are simple, A and B take turns to move. Each round, one of them can only take 1 number away, and then pick out all the divisors of the choosed number. When anyone who can not take away 1 number any longer, he will fail the whole game.
Input
There are multiple cases. Each case include an integer number n (0 ≤ n ≤ 100).
Output
For each case, A win, output "win". If not, output"fail".
Sample Input1
34
Sample Output1
winwin
Author: ZHANG, Yunxiao
Source: ZOJ Monthly, July 2014
#include <iostream>#include <stdio.h>#include <math.h>#include <stdlib.h>#include <string>#include <string.h>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <stack>using namespace std;typedef long long LL;const int INF=0x7fffffff;const int MAX_N=10000;int a;int main(){ while(cin>>a){ if(a==0)printf("fail\n"); else printf("win\n"); } return 0;}
- zoj3882 Help Bob 博弈
- ZOJ3882.Help Bob
- ZOJ Help Bob 3882【博弈】
- zoj 3882 Help Bob(博弈)
- (博弈)Help Bob (141 - ZOJ Monthly, July 2015 )
- ZOJ 3882Help Bob
- zoj 3882 Help Bob
- ZOJ-3882 Help Bob
- Georgia and Bob---博弈
- ZOJ 月赛 Help Bob
- (zoj 3882 Help Bob)<>
- 【博弈】poj1704 Georgia and Bob
- 【Hrbust】 Alice and Bob (博弈)
- [UVALive5760] Alice and Bob && 博弈
- Alice and Bob(博弈)
- hdu4111Alice and Bob+SG博弈
- 【博弈】Alice and Bob CodeForces
- Help Bob (141 - ZOJ Monthly, July 2015 )
- PID参数的整定
- linux tar打包指令
- 长按、捏合、旋转手势的组合应用及ios8新特性
- 向datagrid中动态添加不重复的记录,easyuidatagrid添加
- 第4周项目5--循环双链表应用
- zoj3882 Help Bob 博弈
- 难题总结及解决方法
- 使用OpenRowSet操作Excel
- 搬家了(http://13kv.com/)
- DirectX11 曲面细分阶段
- codeforces 320c A Problem about Polyline(数学)
- 看《淘宝技术这十年》有感
- 斐波那契数列之堆栈法与递归法的耗时比较
- hashmap的存储机制