取(2堆)石子游戏
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2054 Accepted Submission(s): 1238
Problem Description
有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。如果你胜,你第1次怎样取子?
Input
输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石子的数目,a和b都不大于1,000,000,且a<=b。a=b=0退出。
Output
输出也有若干行,如果最后你是败者,则为0,反之,输出1,并输出使你胜的你第1次取石子后剩下的两堆石子的数量x,y,x<=y。如果在任意的一堆中取走石子能胜同时在两堆中同时取走相同数量的石子也能胜,先输出取走相同数量的石子的情况.
Sample Input
1 2 5 8 4 7 2 2 0 0
Sample Output
0 1 4 7 3 5 0 1 0 0 1 2
Author
Zhousc
Source
题意:中文题.....不说话.......
分析:题是基础题,但是要懂具体是怎么拿的,不懂的话.....就暴力嘛,这数据也不大嘛.....
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 1e9;
const int MOD = 1e9+7;
#define ll long long
#define CL(a,b) memset(a,b,sizeof(a))
#define lson (i<<1)
#define rson ((i<<1)|1)
#define N 50010
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main()
{
int n,m,a,b,k;
double x = (1 + sqrt(5.0))/2.0;
while(scanf("%d%d",&a,&b),(a+b))
{
if(a>b) swap(a, b);
k = b-a;
if(a==(int)(k*x)) cout<<0<<endl;
else
{
cout<<1<<endl;
for(int i=1; i<=a; i++)
{
n = a-i;
m = b-i;
k = m-n;
if(n==(int)(k*x)) cout<<n<<" "<<m<<endl;
}
for(int i=b-1; i>=0; i--)
{
n = a;
m = i;
if(n>m) swap(n, m);
k = m-n;
if(n==(int)(k*x)) cout<<n<<" "<<m<<endl;
}
}
}
return 0;
}