| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:runtime error 无语啊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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator