7-17 Horse Racing (25分) 赛马

7-17 Horse Racing (25分)

There is a horse racing between QW and TJ. SB is to be the judge. QW and TJ both have horses. Each horse has an ability that is different from any other one. They arrange their horses in a fixed order. The first horse of QW’s will compete to the first of TJ’s, the second to the second, and so on. Horse with higher ability will beat horse with lower ability. During the n rounds of racings, the one who win most of them will win finally. The loser will lost his horses. Of course, draw game is probably to happen in which situation SB will get all the horses. You should tell SB if he has chance to get the horses.

Input:
The first line contains an integer n. 1<=n<=100.
The second line contains n integers representing the ability of QW’s horses.
The third line also contains n integers representing the ability of TJ’s horses.

Output:
If draw game is possible to happen, print “YES”, else print “NO”.

Sample Input:

4
1 2 7 8
3 4 5 6
2
1 2
3 4

Sample Output:

YES
NO

对两组马按照升序排序,令QW的前一半马和TJ的后一半马进行比较,QW的后一半马和TJ的前一半马进行比较,以达到贪心的目的。

#include<bits/stdc++.h>
using namespace std;
int a[105], b[105];
int main()
{
    int n;
    while(cin >> n){
        for(int i = 0; i < n; i++) cin >> a[i];
        for(int i = 0; i < n; i++) cin >> b[i];
        sort(a, a + n);
        sort(b, b + n);
        int cont1 = 0, cont2 = 0;
        for(int i = 0; i < n / 2; i++){
            if(a[n - 1 - i] > b[n / 2 - 1 - i]) cont1++;
            if(a[n / 2 - 1 - i] < b[n - 1 - i]) cont2++;
        }
        if(n % 2 != 1 && cont1 == cont2) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值