田忌要以最小的代价赢和输
对田忌和齐王的马从小到大各自排序,然后以田忌的马从两边对齐王的扫描,如果小的能赢,就赢,如果不能赢,就比两方最大的马,如果能赢则赢,如果也不能赢
就用最小的和齐王最大的比掉,注意这里不管是否存在平局都保证了最优选择;
#include"stdio.h"
#include"algorithm"
using namespace std;
#define F(i,n) for((i)=0;(i)<(n);i++)
int t[1000],q[1000],n,i,ans,ht,tt,hq,tq;
main()
{
while(scanf("%d",&n)!=EOF&&n)
{
ans=0,ht=0,tt=n-1,hq=0,tq=n-1;
F(i,n)scanf("%d",t+i);
F(i,n)scanf("%d",q+i);
sort(t,t+n);
sort(q,q+n);
F(i,n)
{
if(t[ht]>q[hq])ans++,ht++,hq++;
else if(t[tt]>q[tq])ans++,tt--,tq--;
else ans-=(t[ht]!=q[tq]),ht++,tq--;
}
printf("%d\n",ans*200);
}
return 0;
}