取石子游戏(gcd)

蒜头君和花椰妹在玩一个游戏,他们在地上将n颗石子排成一排,编号为1到n。开始时,蒜头君随机取出了2颗石子扔掉,假设蒜头君取出的2颗石子的编号为a, b。游戏规则如下,蒜头君和花椰妹2人轮流取子,每次取子,假设某人取出的石子编号为i,那么必须要找到一对j,k满足i= j- k或者i= j+k,且编号为j, k的石子已经被取出了,如果谁先不能取石子了,则视为输了。蒜头君比较绅士,让花椰妹先手。

输入格式

第一行输入一个整数t(1 < t≤500),表示蒜头君和花椰妹进行了t局游戏。

对于每局游戏,输入3个整数n(2 < n < 20000),a,b(1 < a,b< n),保证a,b不相等。

输出格式

如果蒜头君赢了游戏,输出一行suantou,如果花椰妹赢了,输入一行huaye。

样例输入

5
8 6 8
9 6 8
10 6 8
11 6 8
12 6 8

样例输出

suantou
suantou
huaye
huaye
suantou

仔细想想欧几里得求 gcd 的过程,最后能取出的石子的编号必然是 gcd(a,b)的倍数的编号。

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <stack>
 9 #include <queue>
10 #include <set>
11 #include <map>
12 #include <sstream>
13 #include <ctime>
14 const int INF=0x3f3f3f3f;
15 typedef long long LL;
16 const int mod=1e9+7;
17 const int maxn=1e5+10;
18 using namespace std;
19 
20 int gcd(int a,int b)
21 {
22     return b?gcd(b,a%b):a;
23 }
24 
25 int main()
26 {
27     #ifdef DEBUG
28     freopen("sample.txt","r",stdin);
29     #endif
30     
31     int T;
32     scanf("%d",&T);
33     while(T--)
34     {
35         int n;
36         scanf("%d",&n);
37         int a,b;
38         scanf("%d %d",&a,&b);
39         if((n/gcd(a,b))&1) printf("huaye\n");
40         else printf("suantou\n");
41     } 
42     
43     return 0;
44 }

-

猜你喜欢

转载自www.cnblogs.com/jiamian/p/12222581.html