日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

*【HDU - 1517】【POJ - 2505】A Multiplication Game(博弈,递推找规律或SG函数)

發布時間:2023/12/10 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 *【HDU - 1517】【POJ - 2505】A Multiplication Game(博弈,递推找规律或SG函数) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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.

解題報告:

? ?SG函數的方法目前還不會?

一個題解:

這里用一種推導的方法來進行求解分析如下:Stan選2-9之間的數如果是2,那么Ollie選的范圍只能在4-18,這樣Stan控制了19 - 4*9;如果是3,那么Ollie選的范圍只能在6-27,這樣Stan控制了28 - 6*9;如果是4,那么Ollie選的范圍只能在8-36,這樣Stan控制了37 - 8*9;如果是5,那么Ollie選的范圍只能在10-45,這樣Stan控制了46 - 10*9;如果是6,那么Ollie選的范圍只能在12-54,這樣Stan控制了55 - 12*9;如果是7,那么Ollie選的范圍只能在14-63,這樣Stan控制了64 - 14*9; 如果是8,那么Ollie選的范圍只能在16-72,這樣Stan控制了73 - 16*9; 如果是9,那么Ollie選的范圍只能在18-81,這樣Stan控制了82 - 18*9;===============綜上:范圍在2 – 9 是Stan win!(2-9)范圍在9+1 – 9*2 是Ollie win!(10-18)范圍在9*2+1 –9*2*9 是Stan win!(19-162)范圍在9*2*9+1 –9*2*9*2 是Ollie win!范圍在9*2*9*2+1 –9*2*9*2*9 是Stan win!........================相信大家看得出規律了吧,范圍左側是上一個范圍的右側加一,右側是上一個右側交替的乘以2和9;

AC代碼:

#include<cstdio> #define ll long long using namespace std; ll n; int main() {while(~scanf("%lld",&n)) {ll cur = 1;bool flag = 0;//=1代表先手 while(cur<n) {//注意162這種邊界,所以不能cur<=nif(!flag) {flag=1;cur*=9;}else {flag=0;cur*=2;}}if(flag) puts("Stan wins.");else puts("Ollie wins.");}return 0 ; }

AC代碼2:

題解

#include <stdio.h> int main() {double n;while(~scanf("%lf",&n)){while(n>18)n/=18;if(n>=1&&n<=9)printf("Stan wins.\n");elseprintf("Ollie wins.\n");}return 0; }

?

總結

以上是生活随笔為你收集整理的*【HDU - 1517】【POJ - 2505】A Multiplication Game(博弈,递推找规律或SG函数)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。