博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【洛谷】P1247取火柴游戏
阅读量:4626 次
发布时间:2019-06-09

本文共 644 字,大约阅读时间需要 2 分钟。

题目链接:

 

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

 

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

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

 

代码:

1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 #define ll long long 7 const int maxn = 500005; 8 9 int n,m,x;10 int a[maxn];11 12 void nim(){13 cin>>n;14 int res = 0;15 for(int i = 1; i<= n; i++){16 cin>>a[i];17 res ^= a[i];18 }19 if(res == 0){20 cout<<"lose"<

 

转载于:https://www.cnblogs.com/Asumi/p/9759712.html

你可能感兴趣的文章
bzoj 5288: [Hnoi2018]游戏
查看>>
清除浮动的方法汇总
查看>>
我县政务网站群建设经验总结
查看>>
站立会议06
查看>>
pyspider遇到的SSL问题
查看>>
Linux用户密码策略
查看>>
轻量级git服务器
查看>>
Java基本知识
查看>>
LinuxC中全局变量environ
查看>>
JAVA第五次作业
查看>>
Stack操作,栈的操作。
查看>>
带返回值的线程Callable
查看>>
百度将与W3C中国召开MIP技术研讨会
查看>>
【Zuul】Zuul过滤器参考资料
查看>>
pytorch简单测试
查看>>
POJ2155(二维树状数组)
查看>>
ssh整合
查看>>
大数组分时加载算法 timedChunk
查看>>
windows下简单使用pip
查看>>
Celery的基本使用
查看>>