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. Spring和Struts2整合

    目的:spring容器管理Action类,代替Servlet 步骤:主要在配置文件 Struts2: 添加支持spring的jar包, 配置<action class="Action类 ...

  2. [WinApi] C#获取其他窗口文本框内容(转)

    声明部分: const int WM_GETTEXT = 0x000D; const int WM_GETTEXTLENGTH = 0x000E; [DllImport("user32.dl ...

  3. Mysql中字段类型不一致导致索引无效

    修改后 详细见楼下链接 http://ustb80.blog.51cto.com/6139482/1287847

  4. js常用关键字和函数

    document.createElement("div"): 创建一个div元素申明一个变量 document.body.appendChild(div);   将创建好的div添 ...

  5. How to install starDIct on suse OS?

    1. Access page http://code.google.com/p/stardict-3/ to download starDict package or use zypper in to ...

  6. python+selenium生成测试报告后自动发送邮件

    标签(空格分隔): 自动化测试 运行自动化脚本后,会产生测试报告,而将测试报告自动发送给相关人员,能够让对方及时的了解测试情况,查看测试结果. 整个脚本包括三个部分: 生成测试报告 获取最新的测试报告 ...

  7. android模拟器没有键盘的解决方法

    刚开始使用android模拟器的时候,发现自己创建的AVD启动后没有出现侧边的键盘,在网上搜索后,发现很多人都有这个问题,也有文章说直接使用PC上的键盘,因为有对应的快捷键.但是,没有键盘,始终不爽! ...

  8. java常见面试题及答案 1-10(基础篇)

    java常见面试题及答案 1.什么是Java虚拟机?为什么Java被称作是"平台无关的编程语言"? Java 虚拟机是一个可以执行 Java 字节码的虚拟机进程.Java 源文件被 ...

  9. 【Android测试】【第十九节】Espresso——API详解

    ◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5997557.html 前言 Espresso的提供了不少A ...

  10. 启动Hive时出现的问题

    Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to i ...