AcWing 1489. 田忌赛马——Java版代码
原题链接
中等
作者:
三玖天下第一
,
2021-02-18 16:37:24
,
所有人可见
,
阅读 720
import java.io.*;
import java.util.*;
public class 田忌赛马 {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
String[] temp;
int num = 50, res;
while(num-- >= 0){
int n = Integer.parseInt(reader.readLine());
if (n == 0) break;
res = 0;
Integer[] t = new Integer[n], g = new Integer[n];
temp = reader.readLine().split(" ");
for (int i = 0; i < n; i++) {
t[i] = Integer.parseInt(temp[i]);
}
temp = reader.readLine().split(" ");
for (int i = 0; i < n; i++) {
g[i] = Integer.parseInt(temp[i]);
}
Arrays.sort(t, (o1,o2)->(o2-o1));
Arrays.sort(g, (o1,o2)->(o2-o1));
int f1 = 0, f2 = 0;
int s1 = n-1, s2 = n-1;
while(f1 <= s1){
if (t[s1] > g[s2]){
s1--;s2--;res++;
}else if (t[s1] < g[s2]){
res --;
s1--;f2++;
}else{
if (t[f1] > g[f2]){
f1++;f2++;res++;
}else {
res += t[s1].compareTo(g[f2]);
s1--;f2++;
}
}
}
System.out.println(res*200);
}
}
}