Sicily 1924. Turn Over the Coins
2015-05-09 11:24
369 查看
题目
思路
这题的题目说得不是很清楚,其实这是一个很经典的翻硬币游戏。
有N个硬币,我们每次先选一个正面朝上的硬币,将其翻转,然后从这个硬币的左边选择0~2个无论正反的硬币翻转。
最后没得翻的人为负者(也即硬币都是反面)。
思路来源于这篇博客:
http://blog.sina.com.cn/s/blog_8f06da99010125ol.html
代码
思路
这题的题目说得不是很清楚,其实这是一个很经典的翻硬币游戏。
有N个硬币,我们每次先选一个正面朝上的硬币,将其翻转,然后从这个硬币的左边选择0~2个无论正反的硬币翻转。
最后没得翻的人为负者(也即硬币都是反面)。
思路来源于这篇博客:
http://blog.sina.com.cn/s/blog_8f06da99010125ol.html
代码
[code]#include <stdio.h> short sg[1005]; void init() { for (int i = 0; i < 1001; i++) { int temp = i << 1; int count = 0; while (temp) { if (temp & 1) count++; temp >>= 1; } sg[i] = (i << 1) + (count & 1); } } int main() { init(); int CaseNum; scanf("%d\n", &CaseNum); while (CaseNum--) { int Ans = 0, k = 0; char text[2005]; gets(text); gets(text); for (int i = 0; text[i] != '\0'; i++) { if (text[i] == 'H') Ans ^= sg[k++]; if (text[i] == 'T') k++; } printf(Ans ? "Alice\n" : "Bob\n"); } return 0; }
相关文章推荐
- The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software
- The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software
- The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software
- The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software by Herb Sutter
- The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software
- The Free Lunch Is Over A Fundamental Turn Toward Concurrency in Software
- The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software 转贴
- Lesson43 Fly over the South Pole
- Map Reduce – the Free Lunch is not over?
- Thinking About "OGL 3 & DX 11: The War Is Over
- Turn the corner
- How do you copy the contents of an array to a std::vector in C++ without looping? (From stack over flow)
- Over-the-air IPhone Setup Using a Signed .mobileconfig File
- codeforces730D Running Over The Bridges(模拟)
- turn back the clock 时光倒转
- 解决“could not find gem 'turn <>=0 ' in any of the gem sources listed in your gemfile”错误
- git提示 error: Your local changes to the following files would be overwritten by merge:
- 关灯看视频(Turn Off the Lights)
- 关灯看视频(Turn Off the Lights)
- POJ3260 The Fewest Coins