解题思路:
要想赢得比赛,胜场数要大于一半;
用 渊子 得快马 去和 对手的快马比(小于渊子的快马)
如果没对手的快,则还用当前的去和对手 次快 的比;直到比对手快,在进行下一匹;
注意事项:
参考代码:
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.length; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < b.length; 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 < 0) 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"); } } }
0.0分
2 人评分
C二级辅导-求偶数和 (C语言代码)浏览:626 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:657 |
【回文数(二)】 (C++代码)浏览:866 |
震宇大神的杀毒软件 (C++代码)浏览:1115 |
C语言训练-计算t=1+1/2+1/3+...+1/n (C语言代码)浏览:862 |
字符串比较 (C语言代码)答案错误????浏览:596 |
C语言程序设计教程(第三版)课后习题6.6 (C语言代码)浏览:624 |
求圆的面积 (C语言代码)浏览:1668 |
1017题解浏览:593 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:679 |