Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 43466 | Accepted: 14760 |
Description
Input
Output
Sample Input
2 1 8 4 4 7
Sample Output
0 1 0
Source
威佐夫博弈(Wythoff's Game)
结论:设a < b,若a = [((√5 + 1)/2 * (b - a))],则为必败局面,否则为必胜局面


1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #include <queue> 7 #include <vector> 8 #include <cmath> 9 #define min(a, b) ((a) < (b) ? (a) : (b)) 10 #define max(a, b) ((a) > (b) ? (a) : (b)) 11 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a)) 12 inline void swap(int &a, int &b) 13 { 14 int tmp = a;a = b;b = tmp; 15 } 16 inline void read(int &x) 17 { 18 x = 0;char ch = getchar(), c = ch; 19 while(ch < '0' || ch > '9') c = ch, ch = getchar(); 20 while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); 21 if(c == '-') x = -x; 22 } 23 24 const int INF = 0x3f3f3f3f; 25 26 int a,b; 27 28 int main() 29 { 30 while(scanf("%d %d", &a, &b) != EOF) 31 { 32 if(a > b) swap(a, b); 33 if((int)(((sqrt(5) + 1.0)/2) * (b - a)) == a) printf("0\n"); 34 else printf("1\n"); 35 } 36 return 0; 37 }
Brave Game
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13313 Accepted Submission(s): 8997
今天,大家选择上机考试,就是一种勇敢(brave)的选择;这个短学期,我们讲的是博弈(game)专题;所以,大家现在玩的也是“勇敢者的游戏”,这也是我命名这个题目的原因。
当然,除了“勇敢”,我还希望看到“诚信”,无论考试成绩如何,希望看到的都是一个真实的结果,我也相信大家一定能做到的~
各位勇敢者要玩的第一个游戏是什么呢?很简单,它是这样定义的:
1、 本游戏是一个二人游戏;
2、 有一堆石子一共有n个;
3、 两人轮流进行;
4、 每走一步可以取走1…m个石子;
5、 最先取光石子的一方为胜;
如果游戏的双方使用的都是最优策略,请输出哪个人能赢。
每组测试数据占一行,包含两个整数n和m(1<=n,m<=1000),n和m的含义见题目描述。
若局面为(m+1)x + r,先手取r,无论后手怎么取,先手总能取成(m+1)x的局面,等到了m + 1,后手最多取m,先手必胜
若局面为(m+1)x,无论先手怎么取,后手总能取成(m+1)x的局面,同上理,后手必胜


1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #include <queue> 7 #include <vector> 8 #include <cmath> 9 #define min(a, b) ((a) < (b) ? (a) : (b)) 10 #define max(a, b) ((a) > (b) ? (a) : (b)) 11 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a)) 12 inline void swap(int &a, int &b) 13 { 14 int tmp = a;a = b;b = tmp; 15 } 16 inline void read(int &x) 17 { 18 x = 0;char ch = getchar(), c = ch; 19 while(ch < '0' || ch > '9') c = ch, ch = getchar(); 20 while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); 21 if(c == '-') x = -x; 22 } 23 24 const int INF = 0x3f3f3f3f; 25 26 int t,n,m; 27 28 int main() 29 { 30 read(t); 31 for(;t;--t) 32 { 33 read(n), read(m); 34 if(n % (m + 1) == 0) printf("second\n"); 35 else printf("first\n"); 36 } 37 return 0; 38 }
尼姆博弈(Nimm Game) 略
斐波那契博弈(Fibonacci Game) 一堆物品,两人轮流去,第一个人不能把物品全取完,以后每个人可以去至少一个至多前面的人取的个数的两倍个
结论:先手胜当且仅当n不是Fibnocci数