当前位置: 代码迷 >> 综合 >> hdu 1052 Tian Ji -- The Horse Racing(贪心)
  详细解决方案

hdu 1052 Tian Ji -- The Horse Racing(贪心)

热度:71   发布时间:2024-01-10 18:48:42.0

借鉴了了别人的思路:

http://www.cnblogs.com/xiaohongmao/p/4059863.html

#include<bits/stdc++.h>
using namespace std;
int a[1005],b[1005] ;
int main()
{int n,i,sum,l1,l2,r1,r2,flag;while(cin>>n){sum=0;if(n==0)break;for( i=1;i<=n;i++){cin>>a[i];}for( i=1;i<=n;i++){cin>>b[i];}sort(a+1,a+n+1);sort(b+1,b+1+n);if(a[1]>b[n]){printf("%d\n",n*200);continue;}else{l1=l2=1;r1=r2=n;while(r1>=l1&&r2>=l2){if(a[r1]>b[r2]){r1--;r2--;sum++;}else if(a[r1]==b[r2]){if(a[l1]<b[l2]){r2--;l1++;sum--;}else if(a[l1]>b[l2]){sum++;l1++;l2++;r1--;r2--;}else{if(b[r2]==a[l1]){break;}else if(b[r2]>a[l1]){l1++;r2--;sum--;}}}else{sum--;l1++;r2--;}}printf("%d\n",sum*200);}}return 0;
}


 


  相关解决方案