首页 > 专题系列 > Java解POJ > POJ 2603 Brave balloonists [解题报告] Java
2013
11-11

POJ 2603 Brave balloonists [解题报告] Java

Brave balloonists

问题描述 :

Ten mathematicians are flying on a balloon over the Pacific ocean. When they are crossing the equator they decide to celebrate this event and open a bottle of champagne. Unfortunately, the cork makes a hole in the balloon. Hydrogen is leaking out and the balloon is descending now. Soon it will fall into the ocean and all the balloonists will be eaten by hungry sharks.

But not everything is lost yet. One of the balloonists can sacrifice himself jumping out, so that his friends would live a little longer. Only one problem still exists ¾ who is the one to get out. There is a fair way to solve this problem. First, each of them writes an integer ai not less than 1 and not more than 10000. Then they calculate the magic number N that is the number of positive integer divisors of the product a1*a2*…*a10. For example, the number of positive integer divisors of 6 is 4 (they are 1,2,3,6). The hero (a mathematician who will be thrown out) is determined according to the last digit of N. Your task is to find this digit.

输入:

Input file contains ten numbers separated by a space.

输出:

Output file should consist of a single digit from 0 to 9 – the last digit of N.

样例输入:

1
2
6
1
3
1
1
1
1
1

样例输出:

9

解题代码:

//* @author: [email protected]
import java.util.Scanner;
public class Main
{
 public static void main(String[] args)
 {
  Scanner in=new Scanner(System.in);
  int[] bb=new int[10000];
  for(int i=0;i< 10;i++)
  {
	int aa=in.nextInt();
	while(aa!=1)
	{
          boolean r=false;
	  for(int j=2;j<=Math.sqrt(aa);j++)
	  {
	    if(aa%j==0){
		aa=aa/j;
		bb[j]++;
		r=true;
		break;
	     }
	   }
	   if(r==false){
		bb[aa]++;
		break;
	   }
	 }
    }
    int total=1;
    for(int i=0;i< 10000;i++)
    {
	if(bb[i]!=0) total*=(bb[i]+1);
    }
    System.out.println(total%10);
  }
}

  1. 第一句可以忽略不计了吧。从第二句开始分析,说明这个花色下的所有牌都会在其它里面出现,那么还剩下♠️和♦️。第三句,可以排除2和7,因为在两种花色里有。现在是第四句,因为♠️还剩下多个,只有是♦️B才能知道答案。

  2. a是根先忽略掉,递归子树。剩下前缀bejkcfghid和后缀jkebfghicd,分拆的原则的是每个子树前缀和后缀的节点个数是一样的,根节点出现在前缀的第一个,后缀的最后一个。根节点b出现后缀的第四个位置,则第一部分为四个节点,前缀bejk,后缀jkeb,剩下的c出现在后缀的倒数第2个,就划分为cfghi和 fghic,第3部分就为c、c

  3. 很高兴你会喜欢这个网站。目前还没有一个开发团队,网站是我一个人在维护,都是用的开源系统,也没有太多需要开发的部分,主要是内容整理。非常感谢你的关注。

  4. 第23行:
    hash = -1是否应该改成hash[s ] = -1

    因为是要把从字符串s的start位到当前位在hash中重置

    修改提交后能accept,但是不修改居然也能accept