HDU ACM 1517 A Multiplication Game

博弈题。

题意:2 人玩游戏,从1 开始,轮流对数进行累乘,直到超过一个指定的值n。

分析:

1、若输入2 ~ 9 ,因为Stan 是先手,所以Stan 必胜

2、若输入10~18 ,因为Ollie 是后手,不管第一次Stan 乘的是什么,Stan肯定在 2 ~ 9 之间,若Stan乘以 2 ,那么Ollie就乘以 9 ,就到18了,若Stan乘以 9 ,那么Ollie乘以大于1的数都都能超过10 ~ 18 中的任何一个数。Ollie 必胜

3、若输入是 19 ~ 162,那么这个范围是 Stan 的必胜态

4、若输入是 163 ~ 324 ,这是又是Ollie的必胜态

5、必胜态是对称的!!!

所以胜负就决定于N了,如果N不断除18后的得到不足18的数M,如果1<M<=9则先手胜利,即Stan wins.如果9<M<=18

则后手胜利.

#include<iostream>
using namespace std;

int main()
{
	double n;

	while(cin>>n)
	{
		while(n>18) n/=18;

		if(n<=9) puts("Stan wins.");
		else puts("Ollie wins.");
	}
    return 0;
}
时间: 2024-11-05 08:11:33

HDU ACM 1517 A Multiplication Game的相关文章

【HDU】1517 A Multiplication Game

http://acm.hdu.edu.cn/showproblem.php?pid=1517 题意:每次乘上2~9..p>=n时赢.. #include <cstdio> #include <cstring> #include <map> using namespace std; typedef long long ll; map<ll, bool> h; ll n; bool dfs(ll p) { if(p>=n) return 0; if(

HDU 1517 A Multiplication Game (博弈-求sg)

A Multiplication Game 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

HDU 1517 A Multiplication Game (博弈&amp;&amp;找规律)

A Multiplication Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3691    Accepted Submission(s): 2097 Problem Description Stan and Ollie play the game of multiplication by multiplying an in

HDU ACM 1103 Flo&#39;s Restaurant

分析:借助STL的min_element实现.每次更新最先被占用的桌子,具体见注释. #include<iostream> #include<algorithm> using namespace std; int main() { int A,B,C; char s[10]; int a[102],b[102],c[102]; int curtime,count,ans; int *p; //桌子最先空闲时间 while(cin>>A>>B>>C

矩阵乘法 --- hdu 4920 : Matrix multiplication

Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 820    Accepted Submission(s): 328 Problem Description Given two matrices A and B of size n×n, find the product of them. b

hdu acm 1425 sort(哈希表思想)

sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25803    Accepted Submission(s): 7764 Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且

HDU ACM 1005 Number Sequence

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 119732    Accepted Submission(s): 29072 Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A

hdu acm 1166 敌兵布阵 (线段树)

敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37903    Accepted Submission(s): 15985 Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务

HDU ACM 1025 Constructing Roads In JGShining&amp;#39;s Kingdom-&amp;gt;二分求解LIS+O(NlogN)

#include<iostream> using namespace std; //BFS+优先队列(打印路径) #define N 500005 int c[N]; int dp[N]; //dp[i]保存的是长度为i的最长不降子序列的最小尾元素 int BS(int n,int x) //二分查找下标,当x比全部元素小时下标为1,比全部元素大时下标为n+1. { int low,high,mid; low=1,high=n; while(low<=high) { mid=(low+h