AC水题,帮忙分析一下,这题怎么才算是赢……

welon123 2010-08-17 06:13:55
[size=16px]http://acm.hdu.edu.cn/showproblem.php?pid=2509

Problem Description
Let's consider m apples divided into n groups. Each group contains no more than 100 apples, arranged in a line. You can take any number of consecutive apples at one time.
For example "@@@" can be turned into "@@" or "@" or "@ @"(two piles). two people get apples one after another and the one who takes the last is
the loser. Fra wants to know in which situations he can win by playing strategies (that is, no matter what action the rival takes, fra will win).



Input
You will be given several cases. Each test case begins with a single number n (1 <= n <= 100), followed by a line with n numbers, the number of apples in each pile. There is a blank line between cases.



Output
If a winning strategies can be found, print a single line with "Yes", otherwise print "No".



Sample Input
2
2 2
1
3


Sample Output
No
Yes
[/size]
...全文
132 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
linsen_519 2010-08-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 baihacker 的回复:]

C/C++ code
int main()
{
for (int caseID = 1, n; scanf("%d", &n) == 1; ++caseID)
{
int sg = 0;
int ones = 0;
for (int i = 0; i < n; ++i)
{
int ……
[/Quote]

飞雪飞雪我爱你!你老霸道了!
baihacker 2010-08-17
  • 打赏
  • 举报
回复
int main()
{
for (int caseID = 1, n; scanf("%d", &n) == 1; ++caseID)
{
int sg = 0;
int ones = 0;
for (int i = 0; i < n; ++i)
{
int t;scanf("%d", &t);
sg ^= t;
ones += t == 1;
}
puts(ones == n && sg == 0 || sg ? "Yes" : "No");
}
return 0;
}


分析见:组合游戏略述——浅谈SG游戏的若干拓展及变形
2.1走完最后一步者输——Anti-SG游戏和SJ定理 在谁走完最后一步谁输时,如何判断输赢? 刚拿到这个问题,大多数人可能会认为要颠覆传统的SG函数解法,设计新的评估函数。 我们不妨先从最本质的nim游戏寻找突破口。
[定义](anti-nim游戏)  桌子上有N堆石子,游戏者轮流取石子。  每次只能从一堆中取出任意数目的石子,但不能不取。  取走最后一个石子者败。
[结论] 先手必胜当且仅当: (1)所有堆的石子数都为1且游戏的SG值为0; (2)有些堆的石子数大于1且游戏的SG值不为0。

64,643

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧