题目:http://acm.hdu.edu.cn/showproblem.php?pid=1052
题解:http://blog.csdn.net/dgq8211/article/details/7370765
关键的话是要想到从田最慢和齐最慢的比较寻找方案。。。
#include<bits/stdc++.h>
using namespace std;
int tian[1005],qi[1005];
int n;
int main(){
while(cin>>n&&n!=0){
for(int i=0;i<n;++i)
cin>>tian[i];
for(int i=0;i<n;++i)
cin>>qi[i];
sort(tian,tian+n);
sort(qi,qi+n);
int l1=0,l2=0,r1=n-1,r2=n-1;
int s=0;
while(l1<=r1){
if(tian[l1]>qi[l2]){ //田忌最慢马 > 齐王最慢马 ,田最慢vs齐最慢
s+=200;
l1++;
l2++;
}
else if(tian[l1]<qi[l2]){ //田忌最慢马 < 齐王最慢马 ,田最慢vs齐最快(横竖这匹马都会输,不如换走对方一匹最快的)
s-=200;
l1++;
r2--;
}
else{
if(tian[r1]>qi[r2]){ //田忌最慢马 = 齐王最慢马 ,判断要不要牺牲最慢马换走齐最快(不用,因为田最快可以打败齐最快)
s+=200;
r1--;
r2--;
}
else if(tian[l1]==qi[r2]){ //牺牲田最慢换走齐最快,也许田最慢未必慢于齐最快,即平局
l1++;
r2--;
}
else{ //牺牲田最慢换走齐最快
s-=200;
l1++;
r2--;
}
}
}
cout<<s<<endl;
}
return 0;
}