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. Entity Framework 基于方法的查询语法

      实体框架(Entity Framework )是 ADO.NET 中的一套支持开发面向数据的软件应用程序的技术. LINQ to Entities 提供语言集成查询 (LINQ) 支持,它允许开发 ...

  2. wifi万能钥匙自媒体平台开放注册(付注册流程)

    12月13日,有网友爆料,wifi万能钥匙自媒体开放注册,看来自媒体还没有达到饱和阶段,也印证了自媒体时代才刚刚到来.现在这个自媒体的时代,几乎大多互联网企业都开通了自己的自媒体,比较知名的像今日头条 ...

  3. MVC入门第一天

    一.异步的两种方法 用jQ的异步  返回content controllor:return Content(sum.ToString());//这里涉及到一个自动封装的问题 html页:<for ...

  4. 205 Reset Content

    https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html The server has fulfilled the request and the ...

  5. thinkphp留言板例子(多条件查询)

    登录: login.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...

  6. SQL Server 2014 Backup Encryption

    转载自: Microsoft MVP Award Program Blog 来源:Microsoft MVP Award Program Blog 的博客:https://blogs.msdn.mic ...

  7. BasicDataSource的配置参数

    参数 描述 username 传递给JDBC驱动的用于建立连接的用户名 password 传递给JDBC驱动的用于建立连接的密码 url 传递给JDBC驱动的用于建立连接的URL driverClas ...

  8. Android开发环境配置

    由于公司项目需要,最近转做Android开发,这里我来介绍一下Android开发环境的配置过程. 首先,需要下载所需要的软件工具,如下所示: 1.Java:开发基础环境,JDK和JRE这两个都要下载的 ...

  9. angularjs中ng-controller中绑定对象

    <!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Cont ...

  10. 后移动互联网时代:到底还要不要开发一个App?

    后移动互联网时代,到底是什么样的一个时代? 首先,后移动互联网时代中,产生头部应用的几率变小了,像微信这样巨头式的App很难在产生第二个.其次,后移动互联网时代,物联网发展迅速,所有的智能硬件都需要一 ...