您的位置:首页 > 其它

HDU 2177 取(2堆)石子游戏 Wythoff Game 求第一步方案

2015-05-08 16:20 429 查看
题目大意:

就是Wythoff Game, 但是判断胜负之后还要输出方案

大致思路:

首先了解到Wythoff Game的性质:

可以参考 HDU1527

对于每一种方案讨论下一步可能走到的P点位置就行了, 细节问题看代码注释吧, 写的很详细了

代码如下:

Result  :  Accepted     Memory  :  1580 KB     Time  :  0 ms

/*
* Author: Gatevin
* Created Time: 2015/5/8 15:53:15
* File Name: Rin_Tohsaka.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
#define foreach(e, x) for(__typeof(x.begin()) e = x.begin(); e != x.end(); ++e)
#define SHOW_MEMORY(x) cout<<sizeof(x)/(1024*1024.)<<"MB"<<endl

const double gold1 = (1 + sqrt(5.)) / 2;
const double gold2 = (sqrt(5.) - 1) / 2;

int main()
{
int a, b;
while(scanf("%d %d", &a, &b), a || b)
{
int k = floor(a*gold2);
if(floor((k + 1)*gold1) == a)//a = A[k + 1]
k = k + 1;
if(floor(k*gold1) == a)// a = A[k], b = B[k];
if(b == a + k)
{
puts("0");//输了
continue;
}
//否则就要输出方案了
puts("1");
//首先是两个都拿的情况, 必须变成A[b - a], A[b - a] + b - a
int t = floor((b - a)*gold1);//A[b - a]
if(t < a)//可以两个都拿
printf("%d %d\n", t, t + b - a);
//否则只拿一个

//拿b的那堆, a = A[k], 或者a = B[k]
//a = A[k]
if(floor(k*gold1) == a)
if(b > a + k)
printf("%d %d", a, a + k);
//a = B[k]
k = floor(a*gold2*gold2);
if(floor((k + 1)*gold1*gold1) == a) k++;
if(floor(k*gold1*gold1) == a)//a = B[k]
printf("%d %d\n", a - k, a);

//拿a的那堆一定要有b = B[k];
if(a != b)//防止相同的结果出现两次
{
k = floor(b*gold2*gold2);
if(floor((k + 1)*gold1*gold1) == b) k++;
if(floor(k*gold1*gold1) == b && b - k < a)
printf("%d %d\n", a - (b - k), b);
}

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息