-->
当前位置:首页 > 题库 > 正文内容

Luz4年前 (2021-03-05)题库1480
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
作者
李廷元
单位
民用航空飞行学院
代码长度限制
16 KB
时间限制
1000 ms
内存限制
64 MB
#include<iostream>
#include <algorithm>
using namespace std;
/*
4
1 2 7 8
3 4 5 6
2
1 2
3 4
*/
int a[1005];
int b[1005];
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 count1=0;
        int count2=0;
        for(int i=0;i<n/2;i++){
            if(a[n-1-i]>b[n/2-1-i])
				count1++;
            if(a[n/2-1-i]<b[n-1-i])
				count2++;
        }
        if(count1==count2&&n%2!=1)
            cout<<"YES"<<endl;
        else
        	cout<<"NO"<<endl;
    }
    return 0;
}


发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。