Http: // 202.121.199.212/judgeonline/problem. php? Cid = 1078 & pid = 2
Analysis: greedy.
Use our best horse to solve the best horse that can solve each other. If so, we can create a larger room for winning the remaining weak horse.
Tian Ji's horse racing example:
Peer: upper, middle, and lower
US: upper, middle, and lower
We can beat each other and defeat each other. If we fight against each other, we will not be able to win.
Code:
#include <iostream>#include <stdio.h>#include <math.h>#include <algorithm>using namespace std;#define MAXN 1004 int n;int wincnt;int a[MAXN],b[MAXN]; int cmp(int x,int y){ return x>y;} void deal(){ int index=0; int curcnt=0; for(int i=0;i<n;i++){ for(int j=index;j<n;j++){ if(a[i]>b[j]){ index=j+1; curcnt++; break; } } } if(curcnt>=wincnt) printf("YES\n"); else printf("NO\n");} int main(){ //freopen("in.txt","r",stdin); while(scanf("%d",&n)!=EOF){ if( !n ) break; wincnt=n/2+1; // cout<<wincnt<<endl; for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++) scanf("%d",&b[i]); sort(a,a+n,cmp); sort(b,b+n,cmp); deal(); } return 0;}