-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain3.java
More file actions
75 lines (54 loc) · 1.66 KB
/
Main3.java
File metadata and controls
75 lines (54 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package tencent;
import java.util.Scanner;
public class Main3 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = Integer.parseInt(in.nextLine());
for (int i = 0; i < N; i++) {
int M = Integer.parseInt(in.nextLine());
int[] nums = new int[M];
String numsss = in.nextLine();
String[] numList = numsss.split(" ");
for (int j = 0; j < M; j++) {
nums[j] = Integer.parseInt(numList[j]);
}
compute(nums);
}
in.close();
}
private static void compute(int[] nums) {
int result = 0;
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
for (int k = j + 1; k < nums.length; k++) {
boolean success = isTriangle(nums[i], nums[j], nums[k]);
if (success) {
result += 1;
}
}
}
}
System.out.println(result);
}
private static boolean isTriangle(int num1, int num2, int num3) {
int max = Math.max(num1, num2);
max = Math.max(max, num3);
if (max == num1) {
return !fuhe(num1, num2, num3);
} else if (max == num2) {
return !fuhe(num2, num3, num1);
} else if (max == num3) {
return !fuhe(num3, num1, num2);
} else {
return true;
}
}
private static boolean fuhe(int max, int min1, int min2) {
return (min1 + min2) <= max;
}
}
//2
//4
//14 21 94 35
//6
//10 16 87 43 51 75