HDU 1052 Tian Ji -- The Horse Racing
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1052
题意:田忌赛马,贪心
#include<iostream> #include<algorithm> using namespace std; int a[1010],b[1010]; int main() { int n,i; while(scanf("%d",&n)==1&&n) { a[0]=b[0]=0; for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) scanf("%d",&b[i]); sort(a,a+n+1); sort(b,b+n+1); int begin_a=1,begin_b=1,end_a=n,end_b=n,sum=0; for(i=1;i<=n;i++) { if(a[begin_a]>b[begin_b]) sum++,begin_a++,begin_b++; else if(a[begin_a]<b[begin_b]) sum--,begin_a++,end_b--; else if(a[end_a]>b[end_b]) sum++,end_a--,end_b--; else if(a[end_a]<b[end_b]) sum--,begin_a++,end_b--; else if(a[begin_a]<b[end_b]) sum--,begin_a++,end_b--; } printf("%d\n",sum*200); } return 0; }