首页 > 专题系列 > Java解POJ > POJ 2535 Very Simple Problem [解题报告] Java
2013
11-11

POJ 2535 Very Simple Problem [解题报告] Java

Very Simple Problem

问题描述 :

During a preparation of programming contest, its jury is usually faced with many difficult tasks. One of them is to select a problem simple enough to most, if not all, contestants to solve.

The difficulty here lies in diverse meanings of the term “simple” amongst the jury members. So, the jury uses the following procedure to reach a consensus: each member weights each proposed problem with a positive integer “complexity rating” (not necessarily different for different problems). The jury member calls “simplest” those problems that he gave the minimum complexity rating, and “hardest” those problems that he gave the maximum complexity rating.

The ratings received from all jury members are then compared, and a problem is declared as “very simple”, if it was called as “simplest” by more than a half of the jury, and was called as “hardest” by nobody.

输入:

The first line of input file contains integers N and P, the number of jury members and the number of problems. The following N lines contain P integers in range from 0 to 1000 each – the complexity ranks. 1 <= N, P <= 100

输出:

Output file must contain an ordered list of problems called as “very simple”, separated by spaces. If there are no such problems, output must contain a single integer 0 (zero).

样例输入:

4 4
1 1 1 2
5 900 21 40
10 10 9 10
3 4 3 5

样例输出:

3

解题代码:

/* @author: */
import java.util.Scanner;
import java.util.Arrays;
public class Main{
 public static void main(String args[])
{
 Scanner sc=new Scanner(System.in);
 int cnt[]=new int[101];
 int temp[]=new int[101];
 boolean arr[]=new boolean[101];
 int n,p,i,j;
  n=sc.nextInt();
  p=sc.nextInt();
  Arrays.fill(cnt,0);
  Arrays.fill(arr,false);
  for(i=0;i< n;i++)
  {
	int max=0,min=999999;
	for(j=0;j< p;j++)
	{
          temp[j]=sc.nextInt();
          if(max< temp[j])max=temp[j];
	   if(min>temp[j])min=temp[j];
	}
	for(j=0;j< p;j++)
	{
	  if(temp[j]==min) cnt[j]++;
	  if(temp[j]==max) arr[j]=true;
	}
   }
   boolean bb=false;
   for(i=0;i< p;i++)
   {
	if(arr[i]||n/2>=cnt[i]) continue;
	if(bb) System.out.printf(" ");
	System.out.printf("%d",i+1);
	bb=true;
   }
   if(!bb) System.out.println("0");
 }
}

  1. if(j){
    int ans=a ;
    for(int x=j-1;x>=0;x–){
    if(!a ) break;
    ans=min(ans,a );
    sum+=ans;
    }
    }
    求解释,,dp的思路是什么呢?

  2. 代码是给出了,但是解析的也太不清晰了吧!如 13 abejkcfghid jkebfghicda
    第一步拆分为 三部分 (bejk, cfghi, d) * C(13,3),为什么要这样拆分,原则是什么?

  3. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.

  4. 你的理解应该是:即使主持人拿走一个箱子对结果没有影响。这样想,主持人拿走的箱子只是没有影响到你初始选择的那个箱子中有奖品的概率,但是改变了其余两个箱子的概率分布。由 1/3,1/3 变成了 0, 2/3