博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1517
阅读量:5318 次
发布时间:2019-06-14

本文共 1442 字,大约阅读时间需要 4 分钟。

A Multiplication Game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2594    Accepted Submission(s): 1477

Problem Description
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.
 
Input
Each line of input contains one integer number n.
 
Output
For 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.
 
分析:
1~9(必胜)10~18(9*2)(必败) 19~162(18*9)(必胜).......由此可看出规律
 
代码如下:
#include<iostream>
using namespace std
;
const
__int64 Max
=
4294967295
;
__int64
a
[
15
];
void
Init
()
{
    int
i
=
2
;
    int
c
=
1
;
    a
[
1
]=
1
;
    for
(i
=
2
;;i
++)
    {
        if
(c
)
        {
            a
[i
]=a
[i
-
1
]*
9
;
            if
(a
[i
]> Max
)
                break
;
        }
        else
        {
            a
[i
]=a
[i
-
1
]*
2
;
            if
(a
[i
]> Max
)
                break
;
        }
        c
=!c
;
    }
}
int
main
()
{
    __int64
n
;
    int
i
;
    Init
();
    while
(~scanf
(
"%I64d"
,&n
))
    {
        for
(i
=
2
;i
<
17
;i
++)
        {
            if
(i
%
2
==
0
)
            {
                if
(n
<=a
[i
])
                {
                    printf
(
"Stan wins.\n"
);
                    break
;
                }
            }
            else
            {
                if
(n
<=a
[i
])
                {
                    printf
(
"Ollie wins.\n"
);
                    break
;
                }
            }
        }
    }
    return
0
;
}
 

转载于:https://www.cnblogs.com/xiong-/archive/2013/05/19/3087604.html

你可能感兴趣的文章
Java 中 String的indexOf 的用法
查看>>
Android Studio打开出现:Default activity not found
查看>>
一次Linux系统被攻击的分析过程
查看>>
Java遗留问题
查看>>
Fugl-Meyer Assessment(FMA)
查看>>
音乐播放器制作(通过数据绑定切换图片)
查看>>
IntelliJ debug grails 无效的解决办法
查看>>
Base64编码
查看>>
01 div+css 为什么需要div+css布局
查看>>
黑马程序员——c语言学习心得——位运算符
查看>>
C# Icon转Byte , Byte转Icon
查看>>
博客开篇,数据转移
查看>>
spring boot 自学笔记(四) Redis集成—Jedis
查看>>
Android应用程序安装过程浅析
查看>>
Crazyflie 2.0 System Architecture
查看>>
用react native 做的一个推酷client
查看>>
B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))
查看>>
Vim 简易配置
查看>>
电梯UI部分
查看>>
2016.07.15
查看>>