很有意思的一道贪心,贴一个写得很好的
博客。
下面是代码
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t=50;
int n;
int h1[1005];
int h2[1005];
int main(){
while(t--){
scanf("%d",&n);
if(n==0)break;
int ans=0;
for(int i=0;i<n;i++)scanf("%d",&h1[i]);
for(int i=0;i<n;i++)scanf("%d",&h2[i]);
sort(h1,h1+n);
sort(h2,h2+n);
int win=0,lose=0;
int t_slow=0,t_fast=n-1;
int k_slow=0,k_fast=n-1;
while(t_slow<=t_fast){
if(h1[t_slow]>h2[k_slow]){
win++;
t_slow++;
k_slow++;
}
else if(h1[t_slow]<h2[k_slow]){
lose++;
t_slow++;
k_fast--;
}
else {
if(h1[t_fast]>h2[k_fast]){
win++;
t_fast--;
k_fast--;
}
else{
if(h1[t_slow]<h2[k_fast])lose++;
t_slow++;
k_fast--;
}
}
}
ans=(win-lose)*200;
printf("%d\n",(win-lose)*200);
}
return 0;
}