SGU 299 Triangle(大数)
来源:互联网 发布:vr眼镜评测 知乎 编辑:程序博客网 时间:2024/06/01 18:46
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
71264810073
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"); } } }
0 0
- SGU 299 Triangle(大数)
- sgu - 269 - Rooks(大数dp)
- SGU - 112 - ab-ba (大数高精度)
- sgu 151 Construct a triangle
- SGU 151 - Construct a triangle
- SGU 200 Cracking RSA (高斯消元+大数高精度)
- SGU 208 Toral Tickets(Polya计数+Java大数)
- SGU 111 大数开根号
- Heron and His Triangle(HDU 6222 找规律+大数)
- SGU 151 Construct a triangle(数学)
- sgu——342(Java做的大数问题(借鉴过来))
- SGU 476 Coach's Trouble 大数模拟
- SGU 112 a^b - b^a 大数+二进制优化
- sgu 112 a^b - b^a java大数
- SGU 481 Hero of Our Time java大数+规律
- SGU 242(MaxFlow)
- SGU 102(Coprimes)
- (sgu-344)Weed
- Android Intent传值反馈,向后传递,要求返回的传值
- SecureCRT 常用命令
- 解决svn一直报Error validating server certificate for https://XXXX fingerprint
- 计算机知识-编程语言对比
- 关于运算符重载的两种方式的优缺点比较
- SGU 299 Triangle(大数)
- Python excel转xml
- 最大子数组问题-GoLang实现
- PostgreSQL 中文资料汇总
- 输出15个数
- TCP服务器和多个客户端传输数据
- 用CSS使div在整个页面中(水平、垂直)都居中——万能的
- 《15个数字的排序代码》15电气1班43号
- bzoj 2724: [Violet 6]蒲公英