HDU 5360 (贪心)

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

题意:告诉你n个区间[ l[i],r[i] ],然后让你排序,必须左区间不大于它前边的总区间个数,右区间不小于前边的总区间个数,求该序列的最大长度以及序列;

PS:场上做的时候,三个人三个思路,不知道为啥交流不力,就这么放过了这道题目;

我的思路:把每个区间当成一个新的区间,就是第i个区间,能做该序列的第几个区间,这样又是一个区间。比如,(0,2)可以做第1,2,3个区间,即1~3;

但是等我实现的时候发现并不好实现,容易超时,因为寻找的时候还是要扫一遍,场下也没细想(再想想,万一能实现呢);

AC:我们大姐头的想法是,按照左区间,右区间降序,然后插入到set里,每次取出最小右区间 和做num(第num个区间)比较,小的话,直接删掉,否则加入序列中。

场上这个题目TLE很多,我们自己都默认不能用STL了。最后也没能转换过这个思路来。

AC

时间: 2024-10-30 12:11:41

HDU 5360 (贪心)的相关文章

hdu 5360 贪心+优先队列

贪心的思路还是比较好想的,每次选择cur(已经邀请成功的人数)所在的区间中右端点最小的(因为右端点大的在后面可以邀请成功的几率大),然后很自然的想到可以用一个优先队列来维护这些区间,只要每次把左端点小于等于cur的区间放到优先队列中即可. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <vector> 5 #include <queue> 6 u

hdu 5360 贪心

#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <stack> #include <set> #include <map> #include <vector> using namespace st

HDU 5360(2015多校6)-Hiking(优先队列)

题目地址:HDU 5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须满足c>=l[i]&&c<=ri,问你邀请的顺序是什么才能使尽可能多的人去远足,若有多个最优解,输出任意的一个. 思路:先按照L从小到到排序,把当前符合的L放入优先队列中 ,然后对队列中的R从小到大排序,贪心的选择R小的,然后乱搞一番就可以了. #include <stdio.h> #include <math.h> #includ

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