NYOJ--364&&HDU--1052

 

原题链接:http://acm.hdu.edu.cn/submit.php?pid=1052

http://acm.nyist.net/JudgeOnline/problem.php?pid=364

分析:当二者最快的马速度相同时,要凭借田忌最慢的马与大王最慢的马的速度关系来确定如何比。

Tian Ji -- The Horse Racing

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<functional>
 4 using namespace std;
 5 int a[1005],b[1005];
 6 int main()
 7 {
 8     int n,i,j,v,front,rear;long s;
 9     while(scanf("%d",&n)==1)
10     {
11         if(n==0)break;
12         v=0;
13         for(i=0;i<n;i++)
14             scanf("%d",&a[i]);
15         for(i=0;i<n;i++)
16             scanf("%d",&b[i]);
17         sort(a,a+n,greater<int>());
18         sort(b,b+n,greater<int>());
19         i=0;j=n-1;front=0;rear=n-1;
20         int T=n;
21         while(T--)
22         {
23             if(a[i]>b[front]){i++;v++;front++;continue;}
24             else if(a[i]<b[front]){j--;front++;v--;continue;}
25             else
26             {
27                 if(a[j]<b[rear]){j--;front++;v--;}
28                 else if(a[j]>b[rear]){j--;rear--;v++;}
29                 else {if(a[j]<b[front])v--;front++;j--;}
30             }
31         }
32         s=200*v;
33         printf("%ld\n",s);
34     }
35     return 0;
36 }

 

posted @ 2013-06-04 18:11  EtheGreat  阅读(149)  评论(0编辑  收藏  举报