首页 新闻 会员 周边

如何解决C - Little Deer and Blue Cat

0
悬赏园豆:100 [待解决问题]

http://acm.uestc.edu.cn/#/contest/show/51

C - Little Deer and Blue Cat

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

 

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 Liby 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, andacerlawson 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
学习编程的峰峰的主页 学习编程的峰峰 | 初学一级 | 园豆:102
提问于:2015-03-26 20:17
< >
分享
所有回答(1)
0

擦擦擦擦。。。。 按错了键了。。。又要重打一边:

 

这题不难,你应该是没看懂题目。核心在于求最大素数问题。

 

1. 如果a,b血量相同,先出手胜。注意每一局先出手顺序是turn的。第一局a先出手,第二句b先出手

2. 如果血量>1,那么寻找小于血量的最大素数,然后血量减去素数,进行下一轮

3. 谁血量先到1,那么必输。

 

举个栗子: a=4,b=4, b先出手

b: 素数3  a=4-3=1

a: 同上 b=1

b:    1     a=1-1=0

b赢了

 

优化:

1. 每一轮计算后,检查血量是否相同,如果相同,参考规则1

2. 求最小素数的函数一定要快!!!!!!!

 

终极优化:

1. 注意 1<a,b<10^8,而且内存占用65m,所以你可以把所有小于10^8的素数找出来,存到数组里,到时候直接用就好了。(10^8个数大概要400m空间,我不知道素数有多少,如果放不完的话,你就可以舍弃部分小的素数)

 

 

个人理解, 欢迎指正

S_SONG | 园豆:202 (菜鸟二级) | 2015-03-27 11:32

对呀 对呀  光是还要判断是否为素数就会超时  又会超限 

我用的埃氏打表法   各种超  T.T T.T

支持(0) 反对(0) 学习编程的峰峰 | 园豆:102 (初学一级) | 2015-03-30 17:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册