-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_125weak.java
More file actions
37 lines (37 loc) · 1.03 KB
/
_125weak.java
File metadata and controls
37 lines (37 loc) · 1.03 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
import java.util.*;
public class _125weak {
static class Row implements Comparable<Row>{
int soldier;
int idx;
public Row(int soldier,int idx){
this.soldier=soldier;
this.idx=idx;
}
@Override
public int compareTo(Row r2){
if(this.soldier==r2.soldier){
return this.idx-r2.idx;
} else{
return this.soldier - r2.soldier;
}
}
}
public static void main(String[] args) {
int army[][]={{1,0,0,0},
{1,1,1,1},
{1,0,0,0},
{1,0,0,0}};
int k=2;
PriorityQueue<Row> pq = new PriorityQueue<>();
for(int i=0;i<army.length;i++){
int count = 0;
for(int j = 0;j<army.length;j++){
count += army[i][j] ==1? 1 : 0;
}
pq.add(new Row(count,i));
}
for(int i =0;i<k;i++){
System.out.println("R" + pq.remove().idx);
}
}
}