開始自己想了多種思路,但最終證明思路有誤,於是去網上看了一下被人的思路,以下是仿照別人的思路寫的
貪心思想(轉載):
1.當田忌最慢的馬比齊王最慢的馬快,贏一場先
2.當田忌最慢的馬比齊王最慢的馬慢,和齊王最快的馬比,輸一場
3.當田忌最快的馬比齊王最快的馬快時,贏一場先。
4.當田忌最快的馬比齊王最快的馬慢時,拿最慢的馬和齊王最快的馬比,輸一場。
5.當田忌最快的馬和齊王最快的馬相等時,拿最慢的馬來和齊王最快的馬比.
#include<stdio.h>
#include<math.h>
#include <queue>
#include<algorithm>
#include <iostream>
#include <string.h>
using namespace std;
const int N=1005;
int num1[N];
int num2[N];
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
int i,j;
for(i=0;i<n;i++)scanf("%d",&num1[i]);
for(i=0;i<n;i++)scanf("%d",&num2[i]);
int ans=0;
int tk=0;
int kk=0;
int tm=n-1;
int km=n-1;
sort(num1,num1+n,greater<int>());
sort(num2,num2+n,greater<int>());
for(i=0;i<n;i++)
{
if(num1[tk]>num2[kk])
{
ans++;
tk++;
kk++;
}
else if(num1[tk]<num2[kk])
{
ans--;
kk++;
tm--;
}
else
{
if(num1[tm]>num2[km])
{
ans++;
tm--;
km--;
}
else if(num1[tm]<num2[km])
{
tm--;
kk++;
ans--;
}
else
{
if(num1[tm]<num2[kk])
{
tm--;
kk++;
ans--;
}
}
}
}
printf("%d\n",ans*200);
}
return 0;
}