基本思路:从大到小排序;枚举田忌的马,一旦能打过齐王的马就打 (不打平局赛),然后统计田忌有多少匹马没有被使用,减去这些金额。
测试样例#2:要求输出361800,实际输出361200.
代码如下:(含测试用cout)
#include <bits/stdc++.h>
using namespace std;
struct horse{
int s;
int c;
};
horse t[2005],q[2005];
bool cmp(horse x,horse y)
{
return x.s>y.s;
}
int main()
{
int n;
cin>>n;
for(int i=1; i<=n; i++) cin>>t[i].s;
for(int i=1; i<=n; i++) cin>>q[i].s;
sort(t+1,t+n+1,cmp);
sort(q+1,q+n+1,cmp);
int ans=0;
int i=1,j=1;
while(j<=n && i<=n)
{
if(t[i].s>q[j].s)
{
ans+=200;
t[i].c=1;
i++;
j++;
}
else j++;
}
for(int k=1; k<=n; k++)
{
if(t[k].c==0)
{
ans-=200;
}
}
cout<<ans;
return 0;
}
感激不尽!