HDU 2176 取(m堆)石子游戏(博弈)

取(m堆)石子游戏

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2283    Accepted Submission(s): 1324


Problem Description
m堆石子,两人轮流取.只能在1堆中取.取完者胜.先取者负输出No.先取者胜输出Yes,然后输出怎样取子.例如5堆 5,7,8,9,10先取者胜,先取者第1次取时可以从有8个的那一堆取走7个剩下1个,也可以从有9个的中那一堆取走9个剩下0个,也可以从有10个的中那一堆取走7个剩下3个.
 

Input
输入有多组.每组第1行是m,m<=200000. 后面m个非零正整数.m=0退出.
 

Output
先取者负输出No.先取者胜输出Yes,然后输出先取者第1次取子的所有方法.如果从有a个石子的堆中取若干个后剩下b个后会胜就输出a b.参看Sample Output.
 

Sample Input
  
  
2 45 45 3 3 6 9 5 5 7 8 9 10 0
 

Sample Output
  
  
No Yes 9 5 Yes 8 1 9 0 10 3
 

Author
Zhousc
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:   2177  1730  1907  1729  2509 
 

Statistic |  Submit |  Discuss | Note





#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define bug printf("hihi\n")

#define eps 1e-7

typedef __int64 ll;

using namespace std;
#define INF 10005

#define N 200005

int a[N];
int n;
vector<pair<int,int> >ans;

int main()
{
    int i,j;
    while(scanf("%d",&n),n)
    {
        int s=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            s^=a[i];
        }

        ans.clear();
        for(int i=1;i<=n;i++)
        {
           int t=s^a[i];
           if(t<=a[i])
             ans.push_back(make_pair(a[i],t));
        }
        if(s==0)
            printf("No\n");
        else
        {
            printf("Yes\n");
            for(int i=0;i<ans.size();i++)
                printf("%d %d\n",ans[i].first,ans[i].second);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值