[HDOJ1052]Tian Ji -- The Horse Racing

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

贪心,田忌的策略比较复杂,仔细想一下可过。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 int main()  {
 7     int n;
 8     int th[1000], qh[1000];
 9     int win = 0;
10     while(scanf("%d", &n), n) {
11         int tmax, tmin, qmax, qmin;
12         win = 0;
13         for(int i = 0; i < n; i++) {
14             scanf("%d", &th[i]);
15         }
16         for(int i = 0; i < n; i++) {
17             scanf("%d", &qh[i]);
18         }
19         sort(th, th+n);
20         sort(qh, qh+n);
21         tmax = n - 1;
22         qmax = n - 1;
23         tmin = 0;
24         qmin = 0;
25         while(tmax >= tmin) {
26             if(th[tmax] > qh[qmax]) {
27                 tmax--;
28                 qmax--;
29                 win++;
30             }
31             else {
32                 if(th[tmin] > qh[qmin]) {
33                     tmin++;
34                     qmin++;
35                     win++;
36                 }
37                 else {
38                     if(th[tmin] < qh[qmax]) {
39                         tmin++;
40                         qmax--;
41                         win--;
42                     }
43                     else {
44                         tmin++;
45                         qmax--;
46                     }
47                 }
48             }
49         }
50         printf("%d\n", win*200);
51     }
52     return 0;
53 }
View Code

 

posted @ 2015-08-29 23:52  Kirai  阅读(155)  评论(0编辑  收藏  举报