1.题目描述:

2068. Game of Nuts

Time limit: 1.0 second
Memory 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

2.题目分析:

又是一道博弈问题。给定一个奇数k,和k个奇数,博弈双方轮流将一个奇数nn分为三个奇数a,b,c,a+b+c==nn,最后拿到全1的那个人输。

1.先假设k=1,这时我们可以用一个bool win[maxn]的数组从i=1开始记录博弈方抽到i时的输赢。

遵循如下规则:win[i] = false, if only if 对每个abc的组合,满足 a+b+c = i, 存在win[a或b或c] = true。

通俗的讲,就是不管如何拆分i,都会给后手留下赢的机会。

现在可以递推一下:

win[1] = false;

win[3] = win[1+1+1] = true;

win[5] = false;

win[7] = win[1+1+5] = true;

win[9] = false;

win[11] = win[1+1+9] = true;

......

win[4n+1] = false && win[4n+3] = true

2.考虑k>1的情况,根据1,我们已经知道拆分一个能赢的数,得到的数都会输,如果能够拆分奇数次,我就会赢,反之会输。设在k个数中,能赢的数有m个,

sum = (k-m)(4n+1)+m(4n+3) = 4nk+k+2m

(sum-k)/2 = 2nk+m

(sum-k)/2 = m(mod2)

3.代码

#include <iostream>

using namespace std;

int main() {
int n, sum, tmp;
cin >> n;
int i;
sum = 0;
for (i = 0; i < n; i++) {
cin >> tmp;
sum += tmp;
}
if ((sum-n)/2 % 2) {
cout << "Daenerys";
} else {
cout << "Stannis";
}
cout << endl;
}

4.心得体会

这种博弈问题,一般都能通过从最简单情况找规律得到一个简单的解法。应该注意观察分析。

Timus 2068. Game of Nuts 解题报告的更多相关文章

  1. codeforces A. Nuts 解题报告

    题目链接:http://codeforces.com/problemset/problem/402/A 题目意思:几经辛苦,终于体明题目噶意思了 = =,完全是考验一个人是否清醒的最简便方法- -! ...

  2. CH Round #56 - 国庆节欢乐赛解题报告

    最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...

  3. 二模13day1解题报告

    二模13day1解题报告 T1.发射站(station) N个发射站,每个发射站有高度hi,发射信号强度vi,每个发射站的信号只会被左和右第一个比他高的收到.现在求收到信号最强的发射站. 我用了时间复 ...

  4. BZOJ 1051 最受欢迎的牛 解题报告

    题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4438  Solved: 2353[S ...

  5. 习题:codevs 2822 爱在心中 解题报告

    这次的解题报告是有关tarjan算法的一道思维量比较大的题目(真的是原创文章,希望管理员不要再把文章移出首页). 这道题蒟蒻以前做过,但是今天由于要复习tarjan算法,于是就看到codevs分类强联 ...

  6. 习题:codevs 1035 火车停留解题报告

    本蒟蒻又来写解题报告了.这次的题目是codevs 1035 火车停留. 题目大意就是给m个火车的到达时间.停留时间和车载货物的价值,车站有n个车道,而火车停留一次车站就会从车载货物价值中获得1%的利润 ...

  7. 习题: codevs 2492 上帝造题的七分钟2 解题报告

    这道题是受到大犇MagHSK的启发我才得以想出来的,蒟蒻觉得自己的代码跟MagHSK大犇的代码完全比不上,所以这里蒟蒻就套用了MagHSK大犇的代码(大家可以关注下我的博客,友情链接就是大犇MagHS ...

  8. 习题:codevs 1519 过路费 解题报告

    今天拿了这道题目练练手,感觉自己代码能力又增强了不少: 我的思路跟别人可能不一样. 首先我们很容易就能看出,我们需要的边就是最小生成树算法kruskal算法求出来的边,其余的边都可以删掉,于是就有了这 ...

  9. NOIP2016提高组解题报告

    NOIP2016提高组解题报告 更正:NOIP day1 T2天天爱跑步 解题思路见代码. NOIP2016代码整合

随机推荐

  1. JavaScript 实现彩票中随机数组的获取

    1.效果图: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  2. SQLite的原子提交原理

    本文描述了sqlite为保证数据库文件不被损坏而采取的种种手段.. 以下是原译者的摘要:http://www.kuqin.com/shuoit/20150618/346693.html 摘要: 本文源 ...

  3. 使用File类列出指定位置的文件信息,包含该路径子目录下的文件信息

    public class Test{ public static void main(String [] args) { File f=new File("d:"); File [ ...

  4. linux服务器使用

    1.在widows系统下,下载putty.exe 配置默认的服务器IP + 端口 添加名称.点击save即可 参考:http://jingyan.baidu.com/article/c74d60004 ...

  5. XSS攻击

    什么是XSS? http://www.cnblogs.com/bangerlee/archive/2013/04/06/3002142.html XSS攻击及防御? http://blog.csdn. ...

  6. Linux将中文目录改为英文

    修改系统语言环境 1.修改系统当前语言环境 export LANG=en_US 2.更新家目录的文件命名 xdg-user-dirs-gtk-update 跳出对话框,提示是否更新成英文,同意即可 3 ...

  7. 关于string.format() 转

    string.format()函数用来生成具有特定格式的字符串,这个函数有两个参数,第一个参数为格式化串:由指示符和控制格式的字符组成.第二个参数是对应格式中每个代号的各种数据. 格式字符串可能包含以 ...

  8. 查找Maven JAR坐标

    http://mvnrepository.com/ http://search.maven.org/

  9. undefined reference to `libiconv_open 无法编译PHP

    解决方法:#wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz#tar -zxvf libiconv-1.13.1.tar. ...

  10. log4j使用快速入门【转】

    1.引言 在应用程序中添加日志记录总的来说基于三个目的: .监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工作 .跟踪代码运行时轨迹,作为日后审计的依据 .担当集成开发环境中的调 ...