题目链接:https://www.luogu.org/problemnew/show/P1247

题意:nim取石子的题意,多了一个判断先手赢的话,输出先手第一把怎么拿,以及拿完之后每堆还剩多少。

题解:异或和为0直接lose。不为0的话,看res xor a[i]的值如果小于a[i]说明可以取该堆,也就是取a[i] - (res xor a[i])这么多。剩余的就是res xor a[i]。

证明。。洛谷题解的大佬写的挺好的。。QAQ

代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define ll long long
const int maxn = ; int n,m,x;
int a[maxn]; void nim(){
cin>>n;
int res = ;
for(int i = ; i<= n; i++){
cin>>a[i];
res ^= a[i];
}
if(res == ){
cout<<"lose"<<endl;
}
else{
//cout<<res<<endl;
for(int i = ; i <= n; i++){
if((a[i]^res) < a[i]){
cout<<(a[i] - (a[i]^res))<<" "<<i<<endl;
a[i] ^= res;
break;
}
}
for(int i = ; i <= n; i++){
cout<<a[i]<<" ";
}
cout<<endl; }
} int main(){
nim();
return ;
}

最新文章

  1. Qml 写的弹出层控件
  2. Mysql:Forcing close of thread xxx user: &#39;root&#39; 的解决方法
  3. checkbox属性checked=&quot;checked&quot;通过js已设置,但是不勾选
  4. oracle日期操作
  5. git Please move or remove them before you can merge. 错误解决方案
  6. phpcms list页实现分页
  7. Linux kernel ‘aac_send_raw_srb’函数输入验证漏洞
  8. Ubuntu14.04+CUDA6.5环境下神经网络工具包Deepnet配置
  9. 最近点对问题 HDU Quoit Design 1007 分治法
  10. Ionic3新特性--页面懒加载2加载其他组件
  11. 笔试常考--浏览器兼容性问题及解决方案(CSS)
  12. spring boot+spring data jpa+gradle+mysql配置问题
  13. web应用与http协议
  14. 第二章 C#语法基础(2.1 C#语言的数据类型一)
  15. git push 和 pull 时 免密执行的方法
  16. Centos7 安装redis集群哨兵模式
  17. 【BZOJ2000】[HNOI2000]取石头游戏(贪心,博弈论)
  18. RAC 11.2的新特性
  19. java.lang.AbstractMethodError: com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsGetGeneratedKeys()Z
  20. CSS之position体验

热门文章

  1. 100个常用js代码(转载)
  2. 36-python基础-python3-字典与列表的区别
  3. CF1228F
  4. MySQL练习题--sqlzoo刷题2
  5. 【css对齐】块内或者行内图片与文字居中对齐最靠谱的方式!
  6. vue组件绑定原生事件
  7. leetcode-12双周赛-1244-力扣排行榜
  8. JS时间差(毫秒/天数/月份)
  9. 【dart学习】-- Dart之函数
  10. 使用PaxScript为Delphi应用增加对脚本的支持