首页 > 专题系列 > Java解POJ > POJ 2027 No Brainer [解题报告] Java
2013
11-10

POJ 2027 No Brainer [解题报告] Java

No Brainer

问题描述 :

Zombies love to eat brains. Yum.

输入:

The first line contains a single integer n indicating the number of data sets.

The following n lines each represent a data set. Each data set will be formatted according to the following description:

A single data set consists of a line “X Y”, where X is the number of brains the zombie eats and Y is the number of brains the zombie requires to stay alive.

输出:

For each data set, there will be exactly one line of output. This line will be “MMM BRAINS” if the number of brains the zombie eats is greater than or equal to the number of brains the zombie requires to stay alive. Otherwise, the line will be “NO BRAINS”.

样例输入:

3
4 5
3 3
4 3

样例输出:

NO BRAINS
MMM BRAINS
MMM BRAINS

解题代码:

import java.util.Scanner;   
  
/**  
 * POJ2027 easy  
 * @author NC  
 */  
public class Main {   
  
    public static void main(String[] args) {   
        Scanner scan = new Scanner(System.in);   
        if (scan.hasNext()) {   
            int n = scan.nextInt();   
            for (int i = 0; i < n; i++) {   
                int a = scan.nextInt();   
                int b = scan.nextInt();   
                if (a >= b) {   
                    System.out.println("MMM BRAINS");   
                } else {   
                        System.out.println("NO BRAINS");   
                }   
            }   
        }   
    }   
}

  1. 第二种想法,我想来好久,为啥需要一个newhead,发现是把最后一个节点一直返回到嘴上面这层函数。厉害,这道题之前没样子想过。

  2. 为什么for循环找到的i一定是素数叻,而且约数定理说的是n=p1^a1*p2^a2*p3^a3*…*pk^ak,而你每次取余都用的是原来的m,也就是n