ural 2068. Game of Nuts
2068. Game of Nuts
Time limit: 1.0 second
Memory limit: 64 MB
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 |
Problem Author: Alexey Danilyuk
Problem Source: Ural Regional School Programming Contest 2015
Problem Source: Ural Regional School Programming Contest 2015
Tags: game
Difficulty: 96
题意:有两个人,n堆石子,每次每人将石子分成三堆(不是平分,divided不是平分的意思,呜呜呜),每堆石子要求分的前后都为奇数,问最后谁胜利
分析:
可以打表SG函数找规律
其实想想,x个石子,(x为奇数)
x = 2k + 1
分成三堆
2k + 1 = (2k1 + 1) + (2k2 + 1) + (2k3 + 1)
= 2(k1+k2+k3+1) + 1
所以当k>=1是才是可分的
注意到k1+k2+k3+1 = k这个形式,
总的来看,这些ki分来分区,只有它们大于1才是可分的,但是每分一次,k1+k2+k3的和会少一
说明这堆石子做多分k次
所以sigma(a[i] div 2),判断奇偶即可
1 /** 2 Create By yzx - stupidboy 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cmath> 8 #include <deque> 9 #include <vector> 10 #include <queue> 11 #include <iostream> 12 #include <algorithm> 13 #include <map> 14 #include <set> 15 #include <ctime> 16 #include <iomanip> 17 using namespace std; 18 typedef long long LL; 19 typedef double DB; 20 #define MIT (2147483647) 21 #define INF (1000000001) 22 #define MLL (1000000000000000001LL) 23 #define sz(x) ((int) (x).size()) 24 #define clr(x, y) memset(x, y, sizeof(x)) 25 #define puf push_front 26 #define pub push_back 27 #define pof pop_front 28 #define pob pop_back 29 #define mk make_pair 30 31 inline int getInt() 32 { 33 int ret = 0; 34 char ch = ' '; 35 bool flag = 0; 36 while(!(ch >= '0' && ch <= '9')) 37 { 38 if(ch == '-') flag ^= 1; 39 ch = getchar(); 40 } 41 while(ch >= '0' && ch <= '9') 42 { 43 ret = ret * 10 + ch - '0'; 44 ch = getchar(); 45 } 46 return flag ? -ret : ret; 47 } 48 49 int n; 50 51 inline void input() 52 { 53 cin >> n; 54 } 55 56 inline void solve() 57 { 58 int x, ans = 0; 59 while(n--) 60 { 61 cin >> x; 62 ans += x / 2; 63 } 64 65 if(ans & 1) cout << "Daenerys" << endl; 66 else cout << "Stannis" << endl; 67 } 68 69 int main() 70 { 71 ios::sync_with_stdio(0); 72 input(); 73 solve(); 74 return 0; 75 }