URAL2068:Game of Nuts(博弈)
2017-03-02 20:03
399 查看
2068. Game of Nuts
Time limit: 1.0 secondMemory limit: 64 MB
The war for Westeros is still in process, manpower and supplies are coming to an end and the winter is as near as never before. The game of thrones is unpredictable so Daenerys and Stannis decided to
determine the true ruler of Seven Kingdoms playing more predictable and shorter game. For example, the game of nuts is the ideal candidate.
Rules of this game are quite simple. Players are given n heaps of nuts. There is an odd number of nuts in each heap. Players alternate turns. In each turn player chooses an arbitrary heap and
divides it into three non-empty heaps so as there is again an odd number of nuts in each heap. The player who cannot make a move loses.
Daenerys has dragons so she moves first. Your task is to determine the winner assuming both Daenerys and Stannis play optimally. Please, do it and stop the war for Westeros!
Input
In the first line there is an odd integer n (1 ≤ n ≤ 777).In the second line there are n integers separated by spaces. These are the amounts of nuts in each heap at the beginning of the game. It is guaranteed that each heap contains not less than
one and not more than 54321 nuts and this amount is an odd number.
Output
Output "Daenerys" (without quotes) in case of Daenerys’ win. Otherwise output "Stannis".Samples
input | output |
---|---|
1 3 | Daenerys |
3 1 1 1 | Stannis |
5 777 313 465 99 1 | Daenerys |
Problem Source: Ural Regional School Programming Contest 2015
题意:有n堆数量均为奇数的石子,轮流操作,选择任意1堆将其分成3堆奇数的石子,轮到谁不能分的就输。
思路:可以猜下套路,考虑若初始有1堆时发现(A类)1,5,9,13,17...先手输,(B类)3,7,11,15...后手输,拓展到多堆的情况,若初始N堆均为A类,显然先手输,因为后手采取最优策略;若N堆均为B类,取N个3测试发现B类的堆数为奇数就赢,偶数就输;然后AB类混合的情况取A类的堆的数量均为1,B类堆的数量均为3,发现A类对结果无影响,因此问题变成统计N个堆中A类堆的数量。
# include <iostream> # include <cstdio> using namespace std; int main() { int n, k; while(~scanf("%d",&n)) { int cnt = 0; while(n--) { scanf("%d",&k); cnt += k>>1; } if(cnt&1) puts("Daenerys"); else puts("Stannis"); } return 0; }
相关文章推荐
- ural 2068 - Game of Nuts 博弈水题
- URAL 2068 Game of Nuts(博弈)
- URAL 2068 Game of Nuts (博弈)
- ural 1923 Another Ecology Problem(博弈dp)
- URAL 2068. Game of Nuts
- UVA - 10891 Game of Sum 区间DP(博弈DP)
- UVA - 10891 Game of Sum 区间DP(博弈DP)循环写法
- URAL 1023 Buttons 博弈
- ural 1928 Another ecology problem 博弈dp
- URAL 1180 Stone Game 博弈 找规律 大数取模 除3取模
- URAL 1023 Buttons 博弈
- (博弈DP) poj 2068
- ural 2068. Game of Nuts
- ural 1180. Stone Game (博弈)
- poj 2068 Nim(博弈dp)
- dp博弈______Nim( poj 2068 )
- HDU 5973 Game of Taking Stones 博弈+高精度
- UVA - 10891 Game of Sum 区间DP博弈
- HDU-5973 Game of Taking Stones(威佐夫博弈+高精度)(C++高精度)
- POJ 2068 Nim (博弈和DP本是一家=-=)