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. Junit测试 - Spring的配置

    第一种: @ContextConfiguration(locations = {"classpath*:/spring-core.xml"}) public class UserM ...

  2. POMDP

    本文转自:http://www.pomdp.org/ 一.Background on POMDPs We assume that the reader is familiar with the val ...

  3. 【iCore3 双核心板】例程三十六:DAC实验——输出直流电压

    实验指导书及代码包下载: http://pan.baidu.com/s/1bRVnzS iCore3 购买链接: https://item.taobao.com/item.htm?id=5242294 ...

  4. Gerrit与Gitlab同步配置replication&其他配置

    一.Gerrit与Gitlab同步配置 当配置好gerrit环境后,还需要与现有gitlab库进行同步配置,否则会影响现有开发与打包流程. 1.安装gerrit replication插件 unzip ...

  5. 微信小程序时代已经来临

    昨天估计微信公众号上产生了第一篇最快的30万+文章,10万+只花了10多分钟.就是冯大辉(著名Oracle专家,知名博主)同学的「微信应用号来了」. 为什么这么一篇如此简单又技术类的文章一下能刷遍朋友 ...

  6. css定位 与position

    本文同时发表于本人个人网站 www.yaoxiaowen.com 在正式讨论position之前,我们需要知道几个概念. 块元素:独占一行的元素.比如div,h1~h6,p等,它是自带换行的. 内联元 ...

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

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

  8. oracle从零开始学习笔记 三

    高级查询 随机返回5条记录 select * from (select ename,job from emp order by dbms_random.value())where rownum< ...

  9. Another MySQL daemon already running with the same unix socket的解决

    问题出现: 每周一需要备份一次数据库,即从服务器MySQL导出sql文件,再导入到我机器上虚拟机的MySQL里.但是今天早上连不上,我进入控制台用#service mysqld start强行启动,报 ...

  10. css3的新特性transform,transition,animation

    一.transform css3引入了一些可以对网页元素进行变换的属性,比如旋转,缩放,移动,或者沿着水平或者垂直方向扭曲(斜切变换)等等.这些的基础都是transform属性 transform属性 ...