3101astronomy

 各位知道什么叫恶心么,就是一道数学题,看半天终于看懂题解了,写个程序出来,然后别人再告诉你要写高精度。。。。。


package p3101;

import java.util.*;
import java.io.*;
import java.math.*;

public class Main{
public static void main(String[] args){
  
  Scanner cin = new Scanner (System.in);
  
  int n;
  int[] t = new int[10005];
  BigInteger[] tmp = new BigInteger[10005];
  BigInteger[] tm = new BigInteger[10005];
  
  n = cin.nextInt();
  for(int i=0; i<n; i++)
   t[i] = cin.nextInt();
  
  Arrays.sort(t, 0, n);
  int cnt = 1;
  for(int i=1; i<n; i++)
   if(t[i] != t[cnt-1]){
    t[cnt++] = t[i];
   }//这个处理是亮点
  cnt--;
  
  
  for(int i=0; i<cnt; i++){
   tmp[i] = BigInteger.valueOf(t[i]).multiply(BigInteger.valueOf(t[cnt]));
   tm[i] = (BigInteger.valueOf(t[cnt]).subtract(BigInteger.valueOf(t[i]))).multiply(BigInteger.valueOf(2));
  }
  
  BigInteger temp1 = tmp[0], temp2 = tm[0];
  BigInteger ans;
  
  for(int i=1;i<cnt; i++){
   temp1 = temp1.multiply(tm[i]);
   tmp[i] = tmp[i].multiply(temp2);
   ans = temp1.gcd(tmp[i]);
   temp1=temp1.multiply(tmp[i]);
         temp1=temp1.divide(ans);
         temp2=temp2.multiply(tm[i]);
         ans=temp1.gcd(temp2);
         temp1=temp1.divide(ans);
         temp2=temp2.divide(ans);
  }
  
  ans = temp1.gcd(temp2);
  System.out.println(temp1.divide(ans)+" "+temp2.divide(ans));
  
  
  
}
}



你可能感兴趣的:(String,Class,import)