Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

测试都通过了啊,为什么通不过

Posted by jsr299 at 2012-08-27 12:37:42
import java.util.*;
public class Main{
	 public static void main(String[] args){
	    Scanner sc=new Scanner(System.in);
	    int m=Integer.parseInt(sc.nextLine());
	    int[] a;
      int total;
	    boolean flag=false;
	    while(m!=0){
	    	  flag=false;
	        a=new int[m];
	        for(int i=0;i<m;i++)
	          a[i]=Integer.parseInt(sc.nextLine());
          total=sharing(a);
	        System.out.println(total+" "+a[0]);
	        m=Integer.parseInt(sc.nextLine());
	    }	
	 }
	 
	 public static boolean judgeEuqals(int[] a){
	   for(int i=0;i<a.length;i++)
	      if(a[i]!=a[0])
	        return false;
	   return true;	
	 }
	 
	 public static int sharing(int[] a){
	 		int count=0,temp;
	 		int[] b=new int[a.length];
	   	while(true){
	        	for(int i=0;i<a.length;i++)
	        	   if(a[i]%2!=0)
	        	     a[i]+=1;
	        	for(int i=0;i<a.length;i++)
	        	    b[(i+1)%a.length]=a[i]/2;
	        	for(int i=0;i<a.length;i++)
	        	   a[i]=a[i]/2+b[i];
	        	if(judgeEuqals(a))
	        	   break;
	          count++;	
	        }
	    return count;
	 }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator