A Multiplication 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.
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.
題意:給一個正整數n(1 < n < 4294967295),p=1,S和O遊戲,兩人輪流對p乘以2-9之間的一個數,首先使p>=n的人獲勝,每次遊戲都從S開始
分析:與其說博弈,不如說是規律。。 這個題看著有點像Nim博弈,想著和9的倍數? 還是別的?
寫了一個,發現不對
然後根據題意列幾個出來
S勝:2-9 (0+2)——9
O勝:10-18 (9+1)——9*2
S勝:19-162 (2*9+1)——9*2*9
O勝:163-324 (9*2*9+1)——9*2*9*2
S勝:324-2916 (9*2*9*2+1)——9*2*9*2*9
……
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
const double INF=0x3f3f3f3f+1.0;
const double eps=1e-6;
const double PI=2.0*acos(0.0);
typedef long long LL;
const int N=305;
int main()
{
LL n,tmp;
while(~scanf("%lld",&n))
{
if(n>1&&n<10)
{
puts("Stan wins.");
continue;
}
LL ans=0,p=1;
while(p<n)
{
// printf("p=%lld ans=%lld\n",p,ans);
if(ans&1) p*=2;
else p*=9;
ans++;
}
printf("%s wins.\n",ans%2?"Stan":"Ollie");
}
return 0;
}
相關文章
- HDU 4951 Multiplication table(找規律)
- HDU 2897-邂逅明下(博弈-SG函式打表找規律)函式
- 【博弈論】HDU - 7216 Triangle GameGAM
- HDU 1847-Good Luck in CET-4 Everybody!(博弈-SG函式/找規律)Go函式
- Codeforces 549C. The Game Of Parity[博弈論]GAM
- EMS單號規律與順豐單號規律(C#)C#
- HDU 1846-Brave Game(巴什博弈-SG函式)GAM函式
- 打表找規律
- HDU 5973-Game of Taking Stones(威佐夫博弈-JAVA BigDecimal)GAMJavaDecimal
- HDU 6298 Maximum Multiple(找規律)
- leedcode-單詞規律
- 圖片跨域規律探尋跨域
- LeetCode-單詞規律LeetCode
- 索引的應用規律總結索引
- Java欄位初始化規律Java
- [6 kyu] Multiplication table
- 軟體開發的21條規律
- LeetCode-290-單詞規律LeetCode
- votedisk在ASM diskgroup上的存放規律ASM
- 博弈論專題——推理與動態規劃相關博弈之POJ2348動態規劃
- Python裡的引用與拷貝規律Python
- python3 中 and 和 or 運算規律Python
- 事理圖譜:事件演化的規律和模式事件模式
- 顧森——《追逐語言的規律》(視訊)
- 一個80後總結就業規律就業
- Shareaholic:社交分享和閱讀的規律
- log_buffer的記憶體分配規律記憶體
- POJ 2311-Cutting Game(Nim博弈-sg函式/記憶化搜尋)GAM函式
- 這款解謎遊戲的開發者是"自然規律"遊戲
- 計算出大小有什麼走勢圖規律
- Touring cities (找規律 哈密爾頓迴路)
- HDU4342 History repeat itself數學規律題
- HDU5139 Formula (找規律+離線處理)ORM
- 程式設計師的成功是否有規律可循?程式設計師
- day01-字串方法-邏輯運算子規律字串
- LeetCode-Sparse Matrix MultiplicationLeetCode
- Codeforces 448D Multiplication Table
- HDU 5795 A Simple Nim (SG函式+打表找規律)函式