HDU 3697贪心

额...大意是你可以决定什么时候选课。然后呢。每五分钟只有一次机会选。每种课限制选课时间。问你能选到的课最多有多少、

感觉一点都不水。是自己太菜了吗?

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6
 7 struct Node
 8 {
 9     int l, r;
10 } node[400];
11
12 int cmp(Node a, Node b)
13 {
14     if (a.r != b.r) return a.r <b.r;
15     return a.l <= b.l;
16 }
17
18 int main()
19 {
20     int n;
21     while(cin >> n)
22     {
23         if (n == 0) break;
24         for (int i=0; i<n; ++i)
25         {
26             cin >> node[i].l >> node[i].r;
27         }
28         sort(node, node+n, cmp);
29         int ans = 0;
30         int vis[400];
31         memset(vis, 0, sizeof(vis));
32
33         for (int i=0; i<5; ++i)
34         {
35             int st = i;
36             int tans = 0;
37             memset(vis, 0, sizeof(vis));
38             //for (st=i; st<=node[n-1].r; st+=5)
39             while(st <= node[n-1].r)
40             {
41                 for (int j=0; j<n; ++j)
42                 {
43                     if (vis[j]) continue;
44                     if (node[j].l < st && node[j].r >= st)
45                     {
46                         //st += 5;
47                         vis[j] = 1;
48                         tans += 1;
49                         break;
50                     }
51                     //st += 5;
52                 }
53                 st += 5;
54             }
55             ans = max(ans, tans);
56         }
57         cout << ans << endl;
58     }
59     return 0;
60 }

时间: 2024-08-10 19:18:30

HDU 3697贪心的相关文章

Selecting courses(hdu 3697 贪心

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3697 因为每隔5分钟选一次 那么枚举0-4就可以 5-1000 都可以由0-4加5加5得到 然后就是题目说可以在非整数点的时候开始 那我们就枚举0.0001,1.0001,2.0001,3.0001,4.0001 这样肯定比枚举0-4可以选择的要多 so 我们for(i=0 to 4) j=i to 1000 每次加5 一个时间段开始的时间要是<=j并且结束时间>j 那就可以选上 (因为假设现在i

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

hdu 1050(贪心算法)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19278    Accepted Submission(s): 6582 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a

HDU2111 Saving HDU 【贪心】

Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5245    Accepted Submission(s): 2397 Problem Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏的商人,XHD不会坐以待毙的. 一天,当他正在苦思冥想解困良策的时