首页 技术 正文
技术 2022年11月12日
0 收藏 690 点赞 4,764 浏览 1674 个字

不难,结果:

poj3101

程序:

import java.math.*;
import java.util.*;public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
while(cin.hasNext())
{
Integer n;
n = cin.nextInt();
long a[] = new long [1005];
BigInteger b[] = new BigInteger [1005];
BigInteger c[] = new BigInteger [1005];
long Maxx = 0;
for(int i = 0; i < n; i++)
{
a[i] = cin.nextLong();
if(a[i]>Maxx) Maxx = a[i];
}
int k = 0;
for(int i = 0; i < n; i++)
{
if(a[i] == Maxx) continue;
else
{
b[i] = BigInteger.valueOf(Maxx * a[i]);
c[i] = BigInteger.valueOf(2 * (Maxx - a[i]));
k = i;
}
}
BigInteger t = BigInteger.ONE;
for(int i = 0; i < n; i++)
{
if (a[i]==Maxx) continue;
t = b[k].multiply(c[i]).gcd(b[i].multiply(c[k]));
b[k] = b[k].multiply(c[i]).multiply(b[i].multiply(c[k])).divide(t);
c[k] = c[k].multiply(c[i]);
t = b[k].gcd(c[k]);
b[k] = b[k].divide(t);
c[k] = c[k].divide(t);
}
System.out.println(b[k]+" "+c[k]);
}
}
}

很邪门的是,时限2000ms,java用了4094ms。。poj3101

另外更邪门的是,下面这个程序在本地,3 1 1 1这组都说除以0。。费解!

import java.math.*;
import java.util.*;public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
while(cin.hasNext())
{
Integer n;
n = cin.nextInt();
BigInteger a[] = new BigInteger [1005];
BigInteger b[] = new BigInteger [1005];
BigInteger c[] = new BigInteger [1005];
BigInteger Maxx = BigInteger.valueOf(0);
for(int i = 0; i < n; i++)
{
a[i] = cin.nextBigInteger();
if(a[i].compareTo(Maxx) == 1) Maxx = a[i];
}
int k = 0;
for(int i = 0; i < n; i++)
{
if(a[i] == Maxx) continue;
else
{
b[i] = Maxx.multiply(a[i]);
c[i] = (Maxx.subtract(a[i])).multiply(BigInteger.valueOf(2));
k = i;
}
}
BigInteger t = BigInteger.ONE;
for(int i = 0; i < n; i++)
{
if (a[i]==Maxx) continue;
t = b[k].multiply(c[i]).gcd(b[i].multiply(c[k]));
b[k] = b[k].multiply(c[i]).multiply(b[i].multiply(c[k])).divide(t);
c[k] = c[k].multiply(c[i]);
t = b[k].gcd(c[k]);
b[k] = b[k].divide(t);
c[k] = c[k].divide(t);
}
System.out.println(b[k]+" "+c[k]);
}
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289