解题思路:
要想赢得比赛,胜场数要大于一半;
用 渊子 得快马 去和 对手的快马比(小于渊子的快马)
如果没对手的快,则还用当前的去和对手 次快 的比;直到比对手快,在进行下一匹;
注意事项:
参考代码:import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
if (n == 0)
break;
int a[] = new int[n]; //渊子
int b[] = new int[n]; //对手
for (int i = 0; i
a[i] = sc.nextInt();
}
for (int i = 0; i
b[i] = sc.nextInt();
}
Arrays.sort(a); //对双人的马按照速度排序(从小到大)
Arrays.sort(b);
int x = b.length - 1; //对手最快的马
int h = 0; //赢得次数
for (int i = n - 1; i >= 0; i--) {
if (x
break;
if (a[i] > b[x]) { //a[i]表示目前渊子最快的马,b[x]对手最快的马
x--;
h++;
} else {
x--;
i++;
}
}
if (h > n / 2)
System.out.println("YES");
else
System.out.println("NO");
}
}
}