| ||||||||||
| 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:3101 用Java 怎么Runtime Error,请教大牛In Reply To:3101 用Java 怎么Runtime Error,请教大牛 Posted by:freesunshine at 2008-09-10 15:23:15 > import java.math.BigInteger;
> import java.util.*;
>
>
> public class Main
> {
> public static void main(String[] args)
> {
> Scanner sc = new Scanner(System.in);
> int n,i;
> int[] pla = new int[1100];
> int[] c = new int[1100];
> int[] d = new int[1100];
> while(sc.hasNext())
> {
> n = sc.nextInt();
> for(i=0;i<n;i++)
> pla[i] = sc.nextInt();
> for(i=0;i<n-1;i++)
> {
> c[i] = pla[i]*pla[n-1];
> d[i] = 2*(pla[i] - pla[n-1]);
> if(d[i] < 0) d[i] = -d[i];
> }
> BigInteger cc = new BigInteger(c[0]+"");
> BigInteger dd = new BigInteger(d[0]+"");
> BigInteger temp = cc.gcd(dd);
> cc = cc.divide(temp);
> dd = dd.divide(temp);
> for(i=1;i<n-1;i++)
> {
> BigInteger k1 = dd, k2 = cc;
> k1 = k1.multiply(new BigInteger(c[i]+""));
> k2 = k2.multiply(new BigInteger(d[i]+""));
> BigInteger gcd = k1.gcd(k2);
> k1 = k1.divide(gcd);
> k2 = k2.divide(gcd);
> cc = cc.multiply(k1);
> gcd = cc.gcd(dd);
> cc = cc.divide(gcd);
> dd = dd.divide(gcd);
> }
> System.out.println(cc+" "+dd);
> }
> }
> }
已经解决了
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator