51nod 1428【贪心】
思路:
就是先排序,然后对每个取最小的结束时间。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e4+10;
struct asd{
int x,y;
};
asd q[N];
int n;
bool cmp(asd a,asd b)
{
if(a.x<b.x) return 1;
if(a.x==b.x)
return a.y<b.y;
return 0;
}
int main()
{
int ans=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&q[i].x,&q[i].y);
sort(q,q+n,cmp);
priority_queue<int,vector<int>,greater<int> >que;
while(!que.empty()) que.pop();
que.push(q[0].y);
ans=1;
for(int i=1;i<n;i++)
{
int x=que.top();
if(q[i].x>=x)
{
que.pop();
que.push(q[i].y);
}
else
{
ans++;
que.push(q[i].y);
}
}
printf("%d\n",ans);
return 0;
}
51nod 1428【贪心】的更多相关文章
- 51nod 1428 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活动安排问题 基准时间限制:1 秒 空间限制:13107 ...
- 51Nod 1428 活动安排问题
51Nod 1428 活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...
- 51nod 1428 活动安排问题 (贪心+优先队列)
来源:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 首先按照开始时间从小到大排序. 其实只要维护一个结束时间的最 ...
- 51nod 1163贪心
用优先队列来贪心,是一个很好地想法.优先队列在很多时候可以维护最值,同时可以考虑到一些其他情况. http://www.51nod.com/onlineJudge/questionCode.html# ...
- 51nod 1625 贪心/思维
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 1625 夹克爷发红包 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1099 贪心/思维
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 1099 任务执行顺序 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1428 活动安排问题(优先队列)
1428 活动安排问题 首先按照开始时间从小到大排序. 其实只要维护一个结束时间的最小堆,每次比较开始时间和堆中最小时间的大小,如果比它大就放入堆中并且时间就要变成当前任务的结束时间, 否则就要新开一 ...
- 51nod 1672 贪心/队列
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1672 1672 区间交 基准时间限制:1 秒 空间限制:131072 K ...
- 51nod 1449 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1449 1449 砝码称重 题目来源: CodeForces 基准时间限制 ...
随机推荐
- [Javascript] Use a custom sort function on an Array in Javascript
Sorting in Javascript with sort uses lexical sorting by default, which means it will sort in alphabe ...
- Android Studio——gradle同步出错:MALFORMED
Android Studio之前使用本地的gradle-2.10,而后创建新的工程总是报错,信息如下: Gradle sync failed: MALFORMED 而后在File->Projec ...
- ActiveMQ(六) 转
package pfs.y2017.m11.mq.activemq.demo07; import org.apache.activemq.ActiveMQConnectionFactory; impo ...
- bzoj 1030: [JSOI2007]文本生成器 (ac自己主动机上的dp)
1030: [JSOI2007]文本生成器 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2635 Solved: 1090 [id=1030&qu ...
- setUp() and setUpBeforeClass()
The @BeforeClass and @AfterClass annotated methods will be run exactly once during your test run - a ...
- 每日五题(Spring)
1使用Spring框架的优点是什么? 控制反转: Spring通过控制反转实现了松散耦合,对象们给出它们的依赖,而不是创建或查找依赖的对象们. 面向切面的编程(AOP): Spring支持面向切面的编 ...
- Printf可变參数使用
參考文档: http://bbs.csdn.net/topics/70288067 Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu 转载请标明来源 本文的二 ...
- 机器学习经典算法具体解释及Python实现--K近邻(KNN)算法
(一)KNN依旧是一种监督学习算法 KNN(K Nearest Neighbors,K近邻 )算法是机器学习全部算法中理论最简单.最好理解的.KNN是一种基于实例的学习,通过计算新数据与训练数据特征值 ...
- WebGIS中地图恢复初始位置及状态
我想实现这么一个效果:地图任意缩放后,点击一个按钮,将立刻回到地图初始加载时的位置,并且是没有缩放的状态. 怎么办呢?最好的办法就是用Home按钮. <!DOCTYPE HTML> < ...
- BZOJ 4197: [Noi2015]寿司晚宴 状态压缩 + 01背包
4197: [Noi2015]寿司晚宴 Time Limit: 10 Sec Memory Limit: 512 MB Description 为了庆祝 NOI 的成功开幕,主办方为大家准备了一场寿 ...