Angwauh


私信TA

用户名:1710113018

访问量:32526

签 名:

你脚下曾踏过的泥沼,是你涤荡着强大的最好印证!

等  级
排  名 95
经  验 8428
参赛次数 6
文章发表 42
年  龄 19
在职情况 在职
学  校 河南农业大学
专  业 软件技术

  自我简介:

解题思路:
要想赢得比赛,胜场数要大于一半;

用  渊子 得快马 去和  对手的快马比(小于渊子的快马)

如果没对手的快,则还用当前的去和对手 次快 的比;直到比对手快,在进行下一匹;

注意事项:

参考代码:

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 人评分

  评论区