当前位置:编程学习 > C/C++ >>

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

 

补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,