码迷,mamicode.com
首页 > 其他好文 > 详细

UESTC_Little Deer and Blue Cat CDOJ 1025

时间:2015-04-25 01:36:05      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

In DOTA, there are two Intellegence heroes. One is Enchantress, who is usually called Little Deer by Chinese players. The other is Storm Spirit, who is usually called Blue Cat by Chinese players.

Well, in UESTC-ACM Team, there are two Intellegent team members. One is acerlawson, who is usually called God Li by others. The other is qzy, who is usually called Master Qiu by others.

One day, qzy and acerlawson are arguing with each other about who is the best DOTA player in the team, so they want to play a game. The game is played in DOTA. However, the rule of the game is quite different from DOTA.

In the game, acerlawson plays Little Deer, and qzy plays Blue Cat. They plays the game in turn, and acerlawson goes first. At frist, Little Deer has A HP, and Blue Cat has B HP. In each hero‘s turn, the hero can choose an integer P and attack the enemy. The enemy will lose P HP. Here P can be 1 or any prime number not greater than the enemy‘s HP. The one whose HP become 0 first will lose the game.

As they are both intellegent, they will make the best choice to win this game. In another word, they will try to kill the other as early as possible.

Your task is really simple: Given A and B, find out who will win this game.

Input

The first line is an integer T(1T1000), the number of test cases.

Then T lines follows.

Each line contains two integers A and B(1A,B108).

Output

For each test case, print God Li if acerlawson will win the game. Otherwise print Master Qiu.

Sample input and output

Sample InputSample Output
3
2 4
4 4
99999989 4
Master Qiu
God Li
Master Qiu

解题报告:

注意到哥德巴赫猜想,任意大于2的偶数必能写成2个素数之和.

so,偶数的情况我们就解决了,那么奇数了?,很显然我们可以得出一个结论:

任意奇数HP的最多三下就GG(扣一点血转换成偶数)

除去素数,那么奇数二下就死如何判断呢?

...do not ask me,i use dp prove that if (x-2) is a prime,he will die in twice

 

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <cmath>
 6 using namespace std;
 7 
 8 bool IsPrime(int x)
 9 {
10   if (x <= 2)
11    return true;
12   int k = sqrt(x) + 1;
13   for(int i = 2 ; i <= k ; ++ i)
14    if ( !(x % i))
15     return false;
16   return true;
17 }
18 
19 int main(int argc,char *argv[])
20 {
21   int Case;
22   scanf("%d",&Case);
23   while(Case--)
24    {
25          int hp1,hp2;
26          int t1,t2;
27          scanf("%d%d",&hp1,&hp2);
28          if ( hp1 % 2 == 0)
29           {
30                 if (hp1 == 2)
31                  t1 = 1;
32                 else
33                  t1 = 2;
34        }
35       else
36        {
37              if (IsPrime(hp1))
38               t1 = 1;
39              else
40               {
41                     if (IsPrime(hp1-2))
42                      t1 = 2;
43                     else
44                      t1 = 3;
45            }
46        }
47       
48       
49       if ( hp2 % 2 == 0)
50           {
51                 if (hp2 == 2)
52                  t2 = 1;
53                 else
54                  t2 = 2;
55        }
56       else
57        {
58              if (IsPrime(hp2))
59               t2 = 1;
60              else
61               {
62                     if (IsPrime(hp2-2))
63                      t2 = 2;
64                     else
65                      t2 = 3;
66            }
67        }
68       if (t1 >= t2)
69        printf("God Li\n");
70       else
71        printf("Master Qiu\n");
72    }
73   return 0;
74 }

 

 

UESTC_Little Deer and Blue Cat CDOJ 1025

标签:

原文地址:http://www.cnblogs.com/Xiper/p/4455101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!