Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18155 Accepted Submission(s): 5281
3 92 83 71 95 87 74 2 20 20 20 20 2 20 19 22 18 0
200 0 0
<span style="font-size:14px;">#include<stdio.h> #include<algorithm> using namespace std; int a[10010],b[10010]; int main() { int n,i,i2,j2,j,count,sum; while(~scanf("%d",&n),n) { for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) scanf("%d",&b[i]); sort(a,a+n); sort(b,b+n); int count=0,i=n-1,j=n-1,i2=0,j2=0,sum=0; while(count++<n) { if(a[i]<b[j]) { sum-=200; i2++;//i不变,j改变接着与齐王后面的马比较,要是能赢田忌再换稍微慢点的马 j--; } else if(a[i]>b[j]) { sum+=200; i--;j--; } else { if(a[i2]>b[j2]) { sum+=200; i2++; j2++; } else { if(a[i2]<b[j])//用最慢的马与齐王最快的马比较 { sum-=200; i2++; j--; } } } } printf("%d\n",sum); } return 0; }</span>
hdu 1052(田忌赛马 贪心算法,sort排序),布布扣,bubuko.com
原文地址:http://blog.csdn.net/ice_alone/article/details/38531879