JZOJ 1984 游戏atlantis
Description–
Atlantis Island 沉没以前,传说中的猫老大和 King 是好朋友……King 很喜欢赌博,这次 King和老朋友猫老大多年不见, 于是便邀请猫老大来玩一个游戏,猫老大应邀参加了。 King 拿出了 n 块黄金(0<n<10^1000002), 猫老大暗自想:咋来这么多钱的„„,现在 King 和猫老大轮流从黄金中拿走一些,每人每次拿走的块数是 2 的次方(例如 1,2,4,8,16……)谁能拿走最后一个黄金,谁就获胜。 现在 King 让猫老大先拿,双方都使用最好的策略来玩的话,谁能取得胜利呢?现在请你来帮助猫老大,他能胜利吗?不仅如此, King 现在提出要和猫老大玩三局,猫老大想知道每局他是否能获胜,并且,你还要告诉猫老大,如果必胜的话,他第一步最少拿走的金块数量。
Input–
三行每行一个数 n(0<n<10^1000002)。
Output–
对于每局, 如果 King 必胜则输出一行“ King will win.”; 否则第一行输出“ MaoLaoDa willwin.”, 第二行输出他第一次拿的最小数量。
Sample Input–
【样例输入 1】
8
4
2
【样例输入 2】
3
8
2
Sample Output–
【样例输出 1】
MaoLaoDa will win.
2
MaoLaoDa will win.
1
MaoLaoDa will win.
2
【样例输出 2】
King will win.
MaoLaoDa will win.
2
MaoLaoDa will win.
2
说明–
【数据范围】
0<n<10^1000002
解题思路–
一开始看到数据规模我。。。
于是就开始找起了规律,(xxhky )
发现,把n mod 3得出的数有点可爱:
- 0:King will win.
- 1:MaoLaoDa will win.第一步最少拿走的金块数量:1
- 2:MaoLaoDa will win.第一步最少拿走的金块数量:2
代码–
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int t,ys;
void read()
{
char c=getchar();
while (c>'9' || c<'0') c=getchar();
while (c<='9' && c>='0')
{
ys=(ys*10+int(c-'0'))%3;
c=getchar();
}
}
int main()
{
freopen("atlantis.in","r",stdin);
freopen("atlantis.out","w",stdout);
for (int i=1;i<=3;++i)
{
t=ys=0;
read();
if (ys==0)
printf("King will win.\n");
else
{
printf("MaoLaoDa will win.\n");
printf("%d\n",ys);//输出余数
}
}
return 0;
}