hdu 1052 贪心

// 判断出(田忌)的必胜局面和必败局面,则可以容易的得到决策方案

// 若没有明显的必胜局面和必败局面,则使用田忌赛马的策略

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 int N;
 4 int v1[1010], v2[1010];
 5
 6 int main()
 7 {
 8     while(scanf("%d", &N) && N) {
 9         int i, j;
10         for(i = 1; i <= N; ++i) {
11             scanf("%d", &v1[i]);
12         }
13         sort(v1 + 1, v1 + 1 + N);
14         for(j = 1; j <= N; ++j) {
15             scanf("%d", &v2[j]);
16         }
17         sort(v2 + 1, v2 + 1 + N);
18
19         int l1, r1, l2, r2;
20         l1 = l2 = 1;
21         r1 = r2 = N;
22         int win_time, lost_time;
23         win_time = lost_time = 0;
24
25         while(l1 <= r1) {
26 //            printf("l1 == %d   r1 == %d   l2 == %d   r2 == %d  win_time == %d  lost_time == %d\n", l1, r1, l2, r2, win_time, lost_time);
27             if(v1[l1] > v2[l2]) {
28                 ++win_time;
29                 ++l1;
30                 ++l2;
31                 continue;
32             }
33             if(v1[l1] < v2[l2]) {
34                 ++lost_time;
35                 ++l1;
36                 --r2;
37                 continue;
38             }
39             if(v1[r1] > v2[r2]) {
40                 ++win_time;
41                 --r1;
42                 --r2;
43                 continue;
44             }
45             if(v1[r1] < v2[r2]) {
46                 ++lost_time;
47                 ++l1;
48                 --r2;
49                 continue;
50             }
51
52             if(v1[l1] == v2[r2]) {
53                 ++l1;
54                 --r2;
55                 continue;
56             }
57             if(v1[l1] < v2[r2]) {
58                 ++lost_time;
59                 ++l1;
60                 --r2;
61                 continue;
62             }
63         }
64         printf("%d\n", (win_time - lost_time) * 200);
65     }
66 }
时间: 2024-11-07 23:24:19

hdu 1052 贪心的相关文章

HDU 1052 贪心+dp

http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 31270    Accepted Submission(s): 9523 Problem Description Here is a fam

HDU 1052 Tian Ji -- The Horse Racing(贪心)(2004 Asia Regional Shanghai)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and

hdu 1052(田忌赛马 贪心算法,sort排序)

Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18155    Accepted Submission(s): 5281 Problem Description Here is a famous story in Chinese history. "That was about

hdu 4105 贪心思想

淋漓尽致的贪心思想 波谷一定是一位数,波峰一位数不够大的时候添加到两位数就一定够大了的. 当在寻找波谷碰到零了就自然当成波谷. 当在寻找波峰时碰到零时,将前面的波谷加到前一个波峰上,让当前的零做波谷,使得波谷的值尽量小,这就是本题最关键的贪心思想,一直想不到. 代码中:a表示前一个值,b表示当前考虑的值,tag为偶数时表示正在寻找波谷,奇数时在寻找波峰. #include<iostream> #include<cstdio> #include<cstring> #inc

HDU 4923 (贪心+证明)

Room and Moor Problem Description PM Room defines a sequence A = {A1, A2,..., AN}, each of which is either 0 or 1. In order to beat him, programmer Moor has to construct another sequence B = {B1, B2,... , BN} of the same length, which satisfies that:

hdu 2037 贪心

今年暑假不AC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 27361    Accepted Submission(s): 14439 Problem Description "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" &quo

HDU 4932 贪心

Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 191    Accepted Submission(s): 38 Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by

hdu 4292 贪心

http://acm.hdu.edu.cn/showproblem.php?pid=4296 Problem Description Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr. Wolowitz, Dr. Blue.Mary has accomplished many great projects, one of which is the Guanghua Building. T

hdu 4442 贪心

http://acm.hdu.edu.cn/showproblem.php?pid=4442 Problem Description WANGPENG is a freshman. He is requested to have a physical examination when entering the university. Now WANGPENG arrives at the hospital. Er-.. There are so many students, and the nu