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]);
        	}
        }
    }
    


  • 相关阅读:
    Mac-Mysql忘记root密码
    spring 定时任务配置
    MD5 加密
    java io流 图片和字符串之间的转换
    httpclient 无信任证书使用https
    java对象转换成json
    Maven仓库 国内镜像
    大数据与批量调度的紧密关系
    开源Datax、Sqoop、Kettle等ETL工具作业自动化实现-分享
    ETL作业调度工具TASKCTL的两个重大突破
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3362362.html
Copyright © 2011-2022 走看看