-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.java
64 lines (54 loc) Β· 1.78 KB
/
Main.java
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
package Implementation.prg85002;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Solution sol = new Solution();
System.out.println(Arrays.toString(sol.solution(new int[]{50, 82, 75, 120}, new String[]{"NLWL", "WNLL", "LWNW", "WWLN"})));
}
}
class Solution {
public int[] solution(int[] weights, String[] head2head) {
int N = weights.length;
Player[] players = new Player[N];
for (int i = 0; i < N; i++) {
players[i] = new Player(i, weights[i]);
int total = 0, win = 0;
for (int j = 0; j < N; j++) {
char c = head2head[i].charAt(j);
if (c == 'N') continue;
if (c == 'W') {
if (weights[j] > weights[i]) players[i].win_heavy ++;
win ++;
}
total ++;
}
if (total > 0) players[i].win_rate = (double) win / total * 100;
}
Arrays.sort(players);
int[] answer = new int[N];
for (int i = 0; i < N; i++) answer[i] = players[i].num + 1;
return answer;
}
}
class Player implements Comparable<Player> {
int num, weight;
double win_rate = 0;
int win_heavy = 0;
public Player(int num, int weight) {
this.num = num;
this.weight = weight;
}
@Override
public int compareTo(Player o) {
if (this.win_rate == o.win_rate) {
if (this.win_heavy == o.win_heavy) {
if (this.weight == o.weight) {
return this.num - o.num;
}
return o.weight - this.weight;
}
return o.win_heavy - this.win_heavy;
}
return Double.compare(o.win_rate, this.win_rate);
}
}