浙江工商 1005 渊子赛马

/* Name: 浙江工商 1005 渊子赛马 Author: UnimenSun Date: 06/06/11 17:56 Description: 模拟 */ /* 解题报告: 1、用渊子的最慢的马与国王最慢的马比,如果能赢则win加1如果不能进入第二步 2、与国王最快的马比,如果国王的赢则lose加1 3、循环上面两步直到渊子的马赛完 注:应先给渊子和国王的马排序从小到大排即可 */ #include <iostream> #include <cstdlib> using namespace std; int cmp(const void *elem1, const void *elem2) { return *(int *)elem1 - *(int *)elem2; } int myself[1001], king[1001]; int n; bool match() { int i; int j = 0; int lose = 0; int win = 0; for(i=0; i<n; ++i) { if(myself[i] <= king[j]) { if(myself[i] < king[n-j-1]) { lose++; } } else { win++; j++; } if(win>n/2 || lose>n/2) break; } if(win > lose) return true; else return false; } int main() { int i; while(cin>>n && n) { for(i=0; i<n; ++i) cin>>myself[i]; for(i=0; i<n; ++i) cin>>king[i]; qsort(myself, n, sizeof(int), cmp); qsort(king, n, sizeof(int), cmp); if(match()) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }

你可能感兴趣的:(Date)