[威佐夫博奕模板(胜利者操作)——hdu2177取(2堆)石子游戏](http://acm.hdu.edu.cn/showproblem.php?pid=2177)
AC code
#include <iostream>
#include <string>
#include<cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
const int maxn = 1e6 + 10;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
int a,b;
//已知a,b,k 其一 ,求其他两个参数;
void k_swap(int &k,int &_a,int &_b)
{
_a = floor(k*(1+sqrt(5))/2);
_b = _a+k;
}
void a_swap(int &k,int &_a, int &_b)
{
k = ceil(_a*(sqrt(5)-1)/2);
_b = _a + k;
}
void b_swap(int &k,int &_a, int &_b)
{
k = ceil(_b*(3-sqrt(5))/2);
_a = _b - k;
}
int main()
{
int k;
while(cin >> a >> b)
{
if(a==0&&b==0) break;
if(a==0||b==0)
{
printf("1\n");
printf("0 0\n");
}
int t = a+b;
a = min(a,b);
b = t -a;
k = b - a;
int _a,_b;
k_swap(k,_a,_b);
if(_a == a && _b == b)
printf("0\n");
else {
printf("1\n");
if(_a < a)
printf("%d %d\n",_a,_b);
_a = a;
a_swap(k,_a,_b);
k = _b - _a;
if(_b < b && (_a == floor(k*(1+sqrt(5))/2)))//检验
printf("%d %d\n",_a,_b);
_b = a;
b_swap(k,_a,_b);
k = _b - _a;
if(_a < b && (_a == floor(k*(1+sqrt(5))/2)))
printf("%d %d\n",_a,_b);
if(a == b) continue;//判重
_b = b;
b_swap(k,_a,_b);
k = _b - _a;
if(_a < a &&(_a == floor(k*(1+sqrt(5)/2))))
printf("%d %d\n", _a,_b);
}
}
return 0;
}