zoukankan      html  css  js  c++  java
  • HDU1517 Multiply Game

    Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and so on. Before a game starts, they draw an integer 1 < n < 4294967295 and the winner is who first reaches p >= n. 

    InputEach line of input contains one integer number n. 
    OutputFor each line of input output one line either 

    Stan wins. 

    or 

    Ollie wins. 

    assuming that both of them play perfectly. 
    Sample Input

    162
    17
    34012226

    Sample Output

    Stan wins.
    Ollie wins.
    Stan wins.
    题解:

    由于每次都是从p=1开始的,所以只要判断每个游戏中1为必败点还是必胜点即可。(以下各式 / 均为取上整)
    依照上面所提到的算法,将终结位置,即[n,无穷]标记为必败点;
    然后将所有一步能到达此必败段的点标记为必胜点,即[n/9,n-1]为必胜点;
    然后将只能到达必胜点的点标记为必败点,即[n/9/2,n/9-1]为必败点;
    重复上面2个步骤,直至可以确定1是必胜点还是必败点。



    参考代码:
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 ll n;
     5 int main()
     6 {
     7     while(~scanf("%lld",&n))
     8     {
     9         ll cnt=1;
    10         for(int a=1;a;++a)
    11         {
    12             if(a&1) cnt=cnt*9ll;
    13             else cnt=cnt*2ll;
    14             if(cnt>=n)
    15             {
    16                 if(a&1) puts("Stan wins.");
    17                 else puts("Ollie wins.");
    18                 break;
    19             }
    20         } 
    21     }
    22     return 0;
    23 }
    View Code
  • 相关阅读:
    LNOI2014LCA(树链剖分+离线操作+前缀和)
    CDQ分治与整体二分学习笔记
    BJWC2018上学路线
    NOIP2013火柴排队
    SHOI2008仙人掌图(tarjan+dp)
    作诗(分块)
    COGS314. [NOI2004] 郁闷的出纳员
    bzoj 1691: [Usaco2007 Dec]挑剔的美食家
    COGS1533.[HNOI2002]营业额统计
    bzoj1208: [HNOI2004]宠物收养所
  • 原文地址:https://www.cnblogs.com/csushl/p/10331528.html
Copyright © 2011-2022 走看看