zoukankan      html  css  js  c++  java
  • Game of Nuts

    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".

    Example

    input output
    1
    3
    
    Daenerys
    
    3
    1 1 1
    
    Stannis
    
    5
    777 313 465 99 1
    
    Daenerys

    题意:共有N堆,要求两人先后分大于三的,分成3堆。

    思路:7分成1 1 5 再分5成 1 1 3 再分3 为1 1 1

    大于等于3的进栈

    
    #include <iostream>
    #include <stdio.h>
    #include <deque>
    #include <algorithm>
    using namespace std;
    deque<int>dp;
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            int i,s=0,x;
            for(i=0;i<n;i++)
            {
                scanf("%d",&x);
                dp.push_back(x);
            }
            while(!dp.empty())
            {
                x=dp.front();
                if(x>=3)
                {
                    s++;
                    dp.push_back(x-2);
                }
                dp.pop_front();
            }
            if(s%2==0)
                printf("Stannis
    ");
            else
                printf("Daenerys
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    P1352 没有上司的舞会
    P1879 [USACO06NOV]玉米田Corn Fields
    P1896 [SCOI2005]互不侵犯
    2019寒假纪中happy之旅
    JZOJ 4249. 【五校联考7day1】游戏
    JZOJ 4248. 【五校联考7day1】n染色
    JZOJ 4252. 【五校联考7day2】QYQ的图
    STM32初学Keil4编译时出现 Error:Failed to execute 'BIN40/Armcc'
    STM32初学Keil4编译时出现 Error:Failed to execute 'BIN40/Armcc'
    重踏学习Java路上_Day02(java 基础上)
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702805.html
Copyright © 2011-2022 走看看