加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

SGU 299 Triangle(大数)

发布时间:2021-05-26 17:42:43 所属栏目:大数据 来源:网络整理
导读: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

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

解题思路:

比较坑的位置就是:

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

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读