HDU 1517 A Multiplication Game(博弈找规律)
2016-08-31 18:49
337 查看
传送门
Total Submission(s): 5309 Accepted Submission(s): 3021
[align=left]Problem Description[/align] 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.
[align=left]Input[/align] Each line of input contains one integer number n.
[align=left]Output[/align] For each line of input output one line either
Stan wins.
or
Ollie wins.
assuming that both of them play perfectly.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
题目大意:
说给你一个数 n(n<4294967295), 开始有一个数 p,初始值为 1,现在有两个人在玩一个游戏,每次这个 p 可以乘以 2−9 中的任意一个数,
现在问你的是谁先让这个 n≤p,谁就赢了。
解题思路:
这个题目,其实刚看到的时候也不知道怎么做。因为这也不能用 sg 来做,也不可以转化为 n 个游戏的异或和,那就再纸上分析吧,其实在纸上
画了画就发现规律了:
当这个 2≤n≤9 的时候,一定是先手胜;
当这个 9∗1+1≤n≤9∗2 的时候,一定是后手胜;
当这个 9∗2+1≤n≤9∗2∗9 的时候,一定是先手胜;
当这个 9∗2∗9+1≤n≤9∗2∗9∗2 的时候,一定是后手胜;
当这个 9∗2∗9∗2+1≤n≤9∗2∗9∗2∗9 的时候,一定是先手胜;
通过这些 我们就可以发现一个规律了,所以就可以进行操作了。
My Code:
A Multiplication Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5309 Accepted Submission(s): 3021
[align=left]Problem Description[/align] 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.
[align=left]Input[/align] Each line of input contains one integer number n.
[align=left]Output[/align] For each line of input output one line either
Stan wins.
or
Ollie wins.
assuming that both of them play perfectly.
[align=left]Sample Input[/align]
162 17 34012226
[align=left]Sample Output[/align]
Stan wins. Ollie wins. Stan wins.
题目大意:
说给你一个数 n(n<4294967295), 开始有一个数 p,初始值为 1,现在有两个人在玩一个游戏,每次这个 p 可以乘以 2−9 中的任意一个数,
现在问你的是谁先让这个 n≤p,谁就赢了。
解题思路:
这个题目,其实刚看到的时候也不知道怎么做。因为这也不能用 sg 来做,也不可以转化为 n 个游戏的异或和,那就再纸上分析吧,其实在纸上
画了画就发现规律了:
当这个 2≤n≤9 的时候,一定是先手胜;
当这个 9∗1+1≤n≤9∗2 的时候,一定是后手胜;
当这个 9∗2+1≤n≤9∗2∗9 的时候,一定是先手胜;
当这个 9∗2∗9+1≤n≤9∗2∗9∗2 的时候,一定是后手胜;
当这个 9∗2∗9∗2+1≤n≤9∗2∗9∗2∗9 的时候,一定是先手胜;
通过这些 我们就可以发现一个规律了,所以就可以进行操作了。
My Code:
/** 2016 - 08 - 31 晚上 Author: ITAK Motto: 今日的我要超越昨日的我,明日的我要胜过今日的我, 以创作出更好的代码为目标,不断地超越自己。 **/ #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <algorithm> #include <set> using namespace std; typedef long long LL; typedef unsigned long long ULL; const int INF = 1e9+5; const int MAXN = 1e4+5; const int MOD = 1e9+7; const double eps = 1e-7; const double PI = acos(-1); using namespace std; LL Scan_LL()///输入外挂 { LL res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } int Scan_Int()///输入外挂 { int res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } void Out(LL a)///输出外挂 { if(a>9) Out(a/10); putchar(a%10+'0'); } int main() { LL n; while(cin>>n) { LL ans = 9LL, cnt = 0; while(1) { if(ans >= n) break; if(cnt & 1) ans *= 9; else ans *= 2; cnt++; } if(cnt & 1) puts("Ollie wins."); else puts("Stan wins."); } return 0; }
相关文章推荐
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- HDU 1517 ——A Multiplication Game(博弈)(找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- HDU 1517 A Multiplication Game (博弈、PN态、找规律)*
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- HDU_1517_博弈(巧妙规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game(博弈找规律)
- HDU 1517 A Multiplication Game(博弈)