Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3030 Accepted Submission(s): 1823

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

【题目链接】:http://acm.hdu.edu.cn/showproblem.php?pid=2176

【题解】



先明确,先手胜的话肯定是m堆石子的各个堆石子数异或值不为0;

则枚举第i堆石子,石头数目要减少;

如果其他m-1堆石子的全部异或小于第i堆石子的数目;

则可以把第i堆石子的数目降低到和其他m-1堆石子的全部异或相同的数量;

这样留给对手的全部石子的异或就为0了;对手变成先手了;则对手必败;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int MAXM = 2e5+10;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int m;
LL a[MAXM]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
while (~scanf("%d",&m))
{
if (m==0)
break;
LL tot = 0;
rep1(i,1,m)
{
rel(a[i]);
tot = tot ^ a[i];
}
if (tot!=0)
puts("Yes");
else
puts("No");
rep1(i,1,m)
{
LL temp = tot ^ a[i];
if (a[i]>temp)
printf("%I64d %I64d\n",a[i],temp);
}
}
return 0;
}

最新文章

  1. hibernate三种状态
  2. C#写爬虫,版本V2.1
  3. jquery+ajax实现分页
  4. java中多线程模拟(多生产,多消费,Lock实现同步锁,替代synchronized同步代码块)
  5. 知道创宇研发技能表v3.1
  6. C#正则表达式分组使用
  7. LruCache--远程图片获取与本地缓存
  8. LoadRunner界面分析(二)
  9. 12096 - The SetStack Computer UVA
  10. JQuery事件处理的注意事项
  11. java构造方法的不同
  12. js获取地址栏url以及获取url参数
  13. HTTP各状态消息说明
  14. tr069开源协议EasyCwmp移植
  15. 201521123051 《Java程序设计》第4周学习总结
  16. 客户端 未登录页面 (clearfix 分割线)
  17. Linux内核源码分析 day01——内存寻址
  18. Exp6 信息搜集与漏洞扫描 20164313 杜桂鑫
  19. 解决python logging重复写日志问题
  20. Nginx+IIS简单的部署

热门文章

  1. Spark MLlib LDA 源代码解析
  2. 洛谷 P1599 结算日
  3. oracle 多行转多列查询
  4. TCP的滑动窗口与拥塞窗口
  5. php课程 10-34 目录遍历中的注意事项是什么
  6. Maven 使用Eclipse构建Maven的SpringMVC项目
  7. 4、C++快速入门2
  8. 【例题 6-1 UVA - 210】Concurrency Simulator
  9. swift项目第二天:初始化项目
  10. 【数学】概念的理解 —— 有序对(ordered pair)