加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

poj 3101 Astronomy (大数java)

发布时间:2020-12-14 03:00:47 所属栏目:大数据 来源:网络整理
导读:poj 3101 Astronomy ?? 2011-08-16 21:39:53 |??分类: ?Poj | 举报 | 字号 ? 订阅 Description There are? n ?planets in the planetary system of star X. They orbit star X in circular orbits located in the same plane. Their tangent velocities are

poj 3101 Astronomy??

2011-08-16 21:39:53|??分类:?Poj|举报|字号?订阅

Description

There are?n?planets in the planetary system of star X. They orbit star X in circular orbits located in the same plane. Their tangent velocities are constant. Directions of orbiting of all planets are the same.

Sometimes the event happens in this planetary system which is called?planet parade. It is the moment when all planets and star X are located on the same straight line.

Your task is to find the length of the time interval between two consecutive planet parades.

Input

The first line of the input file contains?n?— the number of planets (2 ≤?n?≤ 1 000).

Second line contains n integer numbers?ti?— the orbiting periods of planets (1 ≤?ti?≤ 10 000). Not all of?ti?are the same.

Output

Output the answer as a common irreducible fraction,separate numerator and denominator by a space.

Sample Input

3  6 2 3

Sample Output

3 1

Hint

Source

Northeastern Europe 2005,Northern Subregion
?
一拿到表示毫无感觉,手贱了下,看了下discuss,豁然开朗!ORZ!!
题意:已知n个点的环绕点X的周期,求出各点转到同一直线上的最短时间
方法:先预处理下,先把周期一样的行星缩成一个,再求出相邻点间相距半圈所需时间 t = t[i]*t[i-1] / ( (t[i] - t[i-1]) * 2 )。然后求出各个半圈时间的最小公倍数为结果
Hint:需大数
?
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,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)); ?? ?? ?? ?} }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读