题意:田忌赛马,赢得话有200,输了-200,平局不变,求他最多能得到多少
思路:如果他的目前最快的马能大于齐王的,那么就用这匹去比,显然这不会比拿比较慢的去比来的差,同样的道理适用在最慢的比较,如果最快的都比齐王最快的差的话,那么就降低损失,用最慢的去比
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1010;
int arr[MAXN],brr[MAXN],n;
int main(){
while (scanf("%d",&n) != EOF && n){
for (int i = 0; i < n; i++)
scanf("%d",&arr[i]);
for (int j = 0; j < n; j++)
scanf("%d",&brr[j]);
sort(arr,arr+n);
sort(brr,brr+n);
int cnt1 = n-1,cnt2 = n-1;
int sign1 = 0,sign2 = 0;
int ans = 0;
for (int i = 0; i < n; i++){
if (arr[cnt1] > brr[cnt2]){
ans += 200;
cnt1--,cnt2--;
}
else {
if (arr[sign1] > brr[sign2]){
ans += 200;
sign1++,sign2++;
}
else if (arr[sign1] == brr[cnt2])
sign1++,cnt2--;
else if (arr[sign1] < brr[cnt2]){
ans -= 200;
sign1++,cnt2--;
}
}
}
printf("%d\n",ans);
}
return 0;
}