zoukankan      html  css  js  c++  java
  • 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。。

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


  • 相关阅读:
    HDU2897( 巴什博奕变形)
    HTML小知识点积累
    几种自己主动运行js代码的方式
    leetcode笔记:Contains Duplicate
    【Nutch基础教程之七】Nutch的2种执行模式:local及deploy
    为什么使用模板
    前端编程提高之旅(十)----表单验证插件与cookie插件
    【HDOJ 5399】Too Simple
    进程间通信之-信号signal--linux内核剖析(九)
    iOS类的合理设计,面向对象思想
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3362362.html
Copyright © 2011-2022 走看看