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;
}
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
#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; }