[博弈 Wythoff Game]poj 1067
http://poj.org/problem?id=1067
如果你认真看了下面的文章和我一样认真看了,那你就一定能弄明白这个博弈是怎么一回事。
http://yjq24.blogbus.com/logs/42826226.html
写代码的时候要注意,为什么要 n = x - y 然后再计算以为那个 (An,Bn)有公式嘛,An-Bn=n这个是关键,我们只需要判断给出的点(相当于一个点,是P/N如果不知道请看上一篇日志,很详细的讲了如何使用P/N这个也适用哦。我们又知道 An=d*n(d=(sqrt(5)+1)/2)所以算出来之后如果是P点,那么就满足An=y,都则就是N点,代码如下:(前面是我习惯的宏什么的,不要理睬。。直接看mmain函数。。后面也不用理睬)
1 #include<iostream>
2 #include<cstdio>
3 #include<iomanip>
4 #include<algorithm>
5 #include<cstring>
6 #include<string>
7 #include<bitset>
8 #include<queue>
9 #include<vector>
10 #include<string>
11 #include<cmath>
12 #include<map>
13 #include<set>
14 #include<stack>
15 #define rep(i,n,m) for(int i=(n);i<=(m);++i)
16 #define re1(i,n) rep(i,1,n)
17 #define re0(i,n) rep(i,0,n)
18 #define RE(a) ((a)*(a))
19 #define SIZE(a) (int((a).size()))
20 #define vv(a) vector<a>
21 #define vi vv(int)
22 #define vl vv(ll)
23 #define vb vv(bool)
24 //count distance 不能用哦,已经定义了。
25 using namespace std;
26 typedef long long ll;
27 template<class T>
28 void inline maxi(T &a,T &b){
29 a=max(a,b);
30 }
31 template<class T>
32 void inline mini(T &a,T &b){
33 a=min(a,b);
34 }
35 void shownum(int n,int m){
36 rep(i,n,m){
37 cout<<setw(6)<<i;
38 }
39 cout<<endl;
40 }
41 template<class T,class P>
42 void fill(T &a,P v){
43 int n=SIZE(a)-1;
44 re0(i,n)
45 a[i]=v;
46 }
47 template<class T,class P>
48 void fill(T *a,P v,int n){
49 re0(i,n-1)
50 a[i]=v;
51 }
52 template<class T>
53 void show(T &a,int n,int m){
54 rep(i,n,m){
55 cout<<setw(6)<<a[i];
56 }
57 cout<<endl;
58 }
59 template<class T>
60 void show(T *a[10],int n,int m){
61 re0(i,n){
62 re0(j,m)
63 cout<<a[i]<<' ';
64 cout<<endl;
65 }
66 }
67 const int maxnum=+1;
68 const int maxint=2147483647;
69 int a[maxnum];
70 void mmain(){
71 int a,b;
72 while(~scanf("%d%d",&a,&b)){
73 if(a < b)
74 swap(a, b);
75 int n = a - b;
76
77 double x = (sqrt( 5.0 ) + 1 ) / 2;
78 if(int(x * n) == b)
79 cout<<0<<endl;
80 else
81 cout<<1<<endl;
82
83 }
84 }
85 //#define codeforces CODEFORCES
86 #define codeforces_input CODEFORCES_FILE
87 #define MANY_TEST CODEFORCES_MANY_TEST
88 #define MANY_TESST 3
89 int main(){
90 #ifdef codeforces
91 #ifdef codeforces_input
92 freopen("input.txt","r",stdin);
93 freopen("output.txt","w",stdout);
94 #endif
95 #ifdef MANY_TEST
96 re1(wwwwwwwwwwwwwwwwwwwww,MANY_TESST)
97 mmain();
98 return 0;
99 #endif
100 #endif
101 mmain();
102 }
2 #include<cstdio>
3 #include<iomanip>
4 #include<algorithm>
5 #include<cstring>
6 #include<string>
7 #include<bitset>
8 #include<queue>
9 #include<vector>
10 #include<string>
11 #include<cmath>
12 #include<map>
13 #include<set>
14 #include<stack>
15 #define rep(i,n,m) for(int i=(n);i<=(m);++i)
16 #define re1(i,n) rep(i,1,n)
17 #define re0(i,n) rep(i,0,n)
18 #define RE(a) ((a)*(a))
19 #define SIZE(a) (int((a).size()))
20 #define vv(a) vector<a>
21 #define vi vv(int)
22 #define vl vv(ll)
23 #define vb vv(bool)
24 //count distance 不能用哦,已经定义了。
25 using namespace std;
26 typedef long long ll;
27 template<class T>
28 void inline maxi(T &a,T &b){
29 a=max(a,b);
30 }
31 template<class T>
32 void inline mini(T &a,T &b){
33 a=min(a,b);
34 }
35 void shownum(int n,int m){
36 rep(i,n,m){
37 cout<<setw(6)<<i;
38 }
39 cout<<endl;
40 }
41 template<class T,class P>
42 void fill(T &a,P v){
43 int n=SIZE(a)-1;
44 re0(i,n)
45 a[i]=v;
46 }
47 template<class T,class P>
48 void fill(T *a,P v,int n){
49 re0(i,n-1)
50 a[i]=v;
51 }
52 template<class T>
53 void show(T &a,int n,int m){
54 rep(i,n,m){
55 cout<<setw(6)<<a[i];
56 }
57 cout<<endl;
58 }
59 template<class T>
60 void show(T *a[10],int n,int m){
61 re0(i,n){
62 re0(j,m)
63 cout<<a[i]<<' ';
64 cout<<endl;
65 }
66 }
67 const int maxnum=+1;
68 const int maxint=2147483647;
69 int a[maxnum];
70 void mmain(){
71 int a,b;
72 while(~scanf("%d%d",&a,&b)){
73 if(a < b)
74 swap(a, b);
75 int n = a - b;
76
77 double x = (sqrt( 5.0 ) + 1 ) / 2;
78 if(int(x * n) == b)
79 cout<<0<<endl;
80 else
81 cout<<1<<endl;
82
83 }
84 }
85 //#define codeforces CODEFORCES
86 #define codeforces_input CODEFORCES_FILE
87 #define MANY_TEST CODEFORCES_MANY_TEST
88 #define MANY_TESST 3
89 int main(){
90 #ifdef codeforces
91 #ifdef codeforces_input
92 freopen("input.txt","r",stdin);
93 freopen("output.txt","w",stdout);
94 #endif
95 #ifdef MANY_TEST
96 re1(wwwwwwwwwwwwwwwwwwwww,MANY_TESST)
97 mmain();
98 return 0;
99 #endif
100 #endif
101 mmain();
102 }