zoukankan      html  css  js  c++  java
  • UESTC_Little Deer and Blue Cat CDOJ 1025

    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
    ");
    70       else
    71        printf("Master Qiu
    ");
    72    }
    73   return 0;
    74 }
    No Pain , No Gain.
  • 相关阅读:
    博客图片上传picgo工具安装配置github图传使用
    安装配置hexo icarus主题配置
    通往远方的道路总是漫长的
    java 关于值引用、地址引用的问题
    Java设计模式の迭代器模式
    Java设计模式の模版方法模式
    vim 常用快捷键(整理版)
    Java设计模式の责任链模式
    Java设计模式の代理模式
    java rmi远程方法调用实例
  • 原文地址:https://www.cnblogs.com/Xiper/p/4455101.html
Copyright © 2011-2022 走看看