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

Re:runtime error 无语啊

Posted by logics_space at 2009-01-06 15:21:30 on Problem 3101
In Reply To:runtime error 无语啊 Posted by:micheal_C at 2009-01-05 19:45:53
runtime error 这样提问谁能帮你解决??!!

给你个代码作参考

import java.util.*;
import java.math.*;
public class Main{
	public static void main(String args[])throws Exception
	{
	  Scanner cin=new Scanner(System.in);
	  int n = cin.nextInt();
	  int num[]=new int[n];
	  int den[]=new int[n];
	  int per[]=new int[n];
	  for(int i = 0; i < n; i++)
		  per[i]=cin.nextInt();
	  Arrays.sort(per);
	  int cnt=1;
	  for(int i = 1; i < n; i++)
		  if(per[i]!=per[cnt-1])per[cnt++]=per[i];
	  for(int i = 0; i < cnt-1; i++)
	  {
		num[i]=per[cnt-1]*per[i];
		den[i]=2*(per[cnt-1] - per[i]);
	  }  
      BigInteger ansn= new BigInteger(num[0]+"");
      BigInteger ansd= new BigInteger(den[0]+"");
	  for(int i = 1; i < cnt-1; i++)
	  { 
		  BigInteger tempn = new BigInteger(num[i]+"");
		  BigInteger tempd = new BigInteger(den[i]+"");
		  ansn=ansn.multiply(tempd);
		  tempn=tempn.multiply(ansd);
		  ansn=lcm(ansn,tempn);
		  ansd=ansd.multiply(tempd);
		  BigInteger g = ansn.gcd(ansd); 
		  ansn=ansn.divide(g);
		  ansd=ansd.divide(g);
	  }
	  BigInteger g = ansn.gcd(ansd); 
	  ansn=ansn.divide(g);
	  ansd=ansd.divide(g);
	  System.out.println(ansn+" "+ansd);
	}
	static BigInteger lcm(BigInteger a,BigInteger b)
	{
		BigInteger c = a.gcd(b);
	    return a.multiply(b).divide(c);
	}
}

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