Tian Ji – The Horse Racing
田忌赛马
http://acm.hdu.edu.cn/showproblem.php?pid=1052
#include<bits/stdc++.h>
using namespace std;
int cmp(int a, int b)
{
return a > b;
}
int main()
{
int a[1009], b[1009];
int n;
while (scanf("%d", &n), n)
{
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n; i++) scanf("%d", &b[i]);
sort(a, a + n, cmp);
sort(b, b + n, cmp);
int th = 0, wh = 0, te = n - 1, we = n - 1;
int win = 0;
while (n--)
{
if (a[th] > b[wh])
{
th++, wh++;
win++;
}
else if (a[te] > b[we])
{
te--, we--;
win++;
}
else if (a[te] < b[wh])
{
te--;
wh++;
win--;
}
}
printf("%d\n", win * 200);
}
return 0;
}