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
  • 相关阅读:
    第五周进度条
    《掌握需求过程》阅读笔记01
    第三周进度条
    问题账户需求分析
    2016年秋季阅读个人计划
    梦断代码阅读笔记03
    软件工程概论课程总结
    Python爬取上交所一年大盘数据
    Python爬取6271家死亡公司数据,看十年创业公司消亡史
    python:王思聪究竟上了多少次热搜?
  • 原文地址:https://www.cnblogs.com/csushl/p/10331528.html
Copyright © 2011-2022 走看看