hdu2177 —— 威佐夫博奕模板(胜利者操作)——hdu2177取(2堆)石子游戏

[威佐夫博奕模板(胜利者操作)——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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值