不难,结果:

程序:

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。。

另外更邪门的是,下面这个程序在本地,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]);
}
}
}

poj3101的更多相关文章

  1. poj分类 很好很有层次感。

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  2. 【转】POJ题目分类推荐 (很好很有层次感)

    OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...

  3. 【转】ACM训练计划

    [转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...

  4. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  5. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  6. acm常见算法及例题

    转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题  初期:一.基本算法:     (1)枚举. (poj17 ...

  7. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  8. 转载 ACM训练计划

    leetcode代码 利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode. ...

  9. ACM算法总结及刷题参考

    参考:http://bbs.byr.cn/#!article/ACM_ICPC/11777 OJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,p ...

随机推荐

  1. iOS runloop 资源汇总-b

    RunLoop 是 iOS 和 OSX 开发中非常基础的一个概念,这篇文章将从 CFRunLoop 的源码入手,介绍 RunLoop 的概念以及底层实现原理.之后会介绍一下在 iOS 中,苹果是如何利 ...

  2. int([x[, base]]) : 将一个字符转换为int类型,base表示进制

    int([x[, base]]) : 将一个字符转换为int类型,base表示进制 >>> int(-12) -12 >>> int(-12.00) -12 > ...

  3. FZU 2140 Forever 0.5

     Problem 2140 Forever 0.5 Accept: 36    Submit: 113    Special JudgeTime Limit: 1000 mSec    Memory ...

  4. 到底DAO是什么?为什么要有它的存在?

    Data Access Object   数据访问接口,就是访问数据库方法的 interface 1. DAO用来封装Data Source的..就比如,Connection conn = DAOFa ...

  5. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-007-定义切面的around advice

    一.注解@AspectJ形式 1. package com.springinaction.springidol; import org.aspectj.lang.ProceedingJoinPoint ...

  6. hdu3006之位压缩

    The Number of set Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. ActionBar官方教程(8)ShareActionProvider与自定义操作项提供器

    Adding an Action Provider Similar to an action view, an action provider replaces an action button wi ...

  8. Formatting is Specified but argument is not IFormattable

    private void DeviceSetText(TextBox textBox, string text) { //处理text的显示值 ") //小数位后保留2位 { //小数点后保 ...

  9. 做最好的自己(Be Your Personal Best)

    成功——做最好的自己 价值观——成功源于诚信 积极主动——成功的选择在于自己 同理心——人际交往的基础 自信——用信心放飞自我 自省——在反思中走向成功 勇气——勇往直前的精神 胸怀——海纳百川的境界 ...

  10. POI导出数据内存溢出问题

    POI之前的版本不支持大数据量处理,如果数据过多则经常报OOM错误,有时候调整JVM大小效果也不是太好.3.8版本的POI新出来了SXSSFWorkbook,可以支持大数据量的操作,只是SXSSFWo ...