SGU 299 Triangle(大数)

Triangle

Description



It is well known that three segments can make a triangle if and only if the sum of lengths of any two of them is strictly greater than the length of the third one. Professor Vasechkin has  N segments. He asked you, if you could find at least one set of three segments among them which can be used by professor to make a triangle.

Input

The first line of the input contains the only integer number  N (3≤  N≤ 1000). The following  N lines contain the length of segments professor has. The length of any segment is the integer number from 1 to 10  500.

Output

Write to the output the length of segments requested by the professor — three numbers delimited by spaces. Write three zeros if there are no such three segments.

Sample Input

sample input
sample output
7
1
2
6
4
8
100
73
8 4 6

解题思路:

比较坑的位置就是:

public class Solution{  

}

AC代码:

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Solution{  
    public static void main(String args[]){  
    	Scanner sca = new Scanner(System.in);
        while(sca.hasNext()){
        	int n = sca.nextInt();
        	BigInteger[] a = new BigInteger[n];
            boolean flag = true;
            for(int i = 0; i < n; i++)
            	a[i] = sca.nextBigInteger();
            Arrays.sort(a);
            for(int i = 0; i < n && flag; i++){
            	for(int j = i+1; j < n-1 && flag; j++){
        			if((a[i].add(a[j])).compareTo(a[j+1]) > 0){
        				flag = false;
        				System.out.println(a[i]+" "+a[j]+" "+a[j+1]);
        			}
            	}
            }
            if(flag)
            	System.out.println("0 0 0");
        }
    }  
}  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值