HDU1517 Multiply Game
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是必胜点还是必败点。
参考代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int main()
{
while(~scanf("%lld",&n))
{
ll cnt=;
for(int a=;a;++a)
{
if(a&) cnt=cnt*9ll;
else cnt=cnt*2ll;
if(cnt>=n)
{
if(a&) puts("Stan wins.");
else puts("Ollie wins.");
break;
}
}
}
return ;
}
HDU1517 Multiply Game的更多相关文章
- Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- [LeetCode] Multiply Strings 字符串相乘
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- 43. Multiply Strings
/** * @param {string} num1 * @param {string} num2 * @return {string} */ var multiply = function(num1 ...
- LeetCode:Multiply Strings
题目链接 Given two numbers represented as strings, return multiplication of the numbers as a string. Not ...
- Numpy Study 2----* dot multiply区别
使用numpy时,跟matlab不同: 1.* dot() multiply() 对于array来说,* 和 dot()运算不同 *是每个元素对应相乘 dot()是矩阵乘法 对于matrix来说,* ...
- 【leetcode】Multiply Strings
Multiply Strings Given two numbers represented as strings, return multiplication of the numbers as a ...
- LeetCode(43. Multiply Strings)
题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note ...
- [CareerCup] 7.4 Implement Multiply Subtract and Divide 实现乘法减法和除法
7.4 Write methods to implement the multiply, subtract, and divide operations for integers. Use only ...
- Java for LeetCode 043 Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
随机推荐
- count的一些用法
count(*)包括了所有的列,相当于行数,在统计结果的时候,不会忽略列值为NULL count(1)包括了所有列,用1代表代码行,在统计结果的时候,不会忽略列值为NULL count(列名)只包 ...
- MySQL的安装+可视化工具+JDBC的增删改查
1.Mysql和可视化工具的安装 安装包网上有很多资源.这里推荐一个我一直在用的学习网站,上面有提供安装包和详细的说明. http://how2j.cn/k/mysql/mysql-install/3 ...
- Netty学习篇⑤--编、解码
前言 学习Netty也有一段时间了,Netty作为一个高性能的异步框架,很多RPC框架也运用到了Netty中的知识,在rpc框架中丰富的数据协议及编解码可以让使用者更加青睐: Netty支持丰富的编解 ...
- python3.7.1安装Scrapy爬虫框架
python3.7.1安装Scrapy爬虫框架 环境:win7(64位), Python3.7.1(64位) 一.安装pyhthon 详见Python环境搭建:http://www.runoob.co ...
- 【前端VUE】【后端SSM】 记录一次多条件查询状态下加载极慢的解决思路和解决方案
最近在开发一个Online Judge系统,其中有一个“挑战模式”模块,如图所示 由于是第一次使用ECharts做开发,所以完成整个模块的过程也是边写边学了,记录一下问题: 遇到的问题:在最开始进行测 ...
- Vue2.x与bootsrap-table动态添加元素和绑定事件无效
一.问题: 最近在使用vue与bootstrap-table结合生成表格时,按以前的经验----每列数据可用formatter:function(value,row,index){}进行一些其 ...
- GitHub注册失败,卡在第一步
同事说他无法注册GitHub,我一开始以为GitHub又无法登录进去,我就登录了自己的GitHub账号,没有问题,可以登录啊,见第一个标签页.同一局域网,不可能我能登录,你无法完成注册啊.于是,我就在 ...
- python2的编码问题小结
对于python2,经常会遇到编码问题,在此小记一下. Python2默认的编码解码方式是ascii码,这点要牢记. windows系统默认是gbk编码的,可以使用chcp查看:936,那就是GBK简 ...
- ubuntu server 1604 设置笔记本盒盖 不操作
sudo vim /etc/systemd/logind.conf //打开配置文件 找到 #HandleLidSwitch=suspend 改为 HandleLidSwitch=ignore ...
- PostGIS 结合Openlayers以及Geoserver实现最短路径分析(一)
环境: Win10 ArcMap10.4(用于数据处理) postgresql9.4 postgis2.2.3 pgRouting2.3(postgresql插件) ##附上本文配套素材下载地址:ht ...