51nod 1428 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428
第一行一个正整数n (n <= 10000)代表活动的个数。
第二行到第(n + 1)行包含n个开始时间和结束时间。
开始时间严格小于结束时间,并且时间都是非负整数,小于1000000000
一行包含一个整数表示最少教室的个数。
3
1 2
3 4
2 9
2
#include<bits/stdc++.h>
using namespace std;
#define LL long long
struct node{int l,r;}P[];
bool cmp(node A,node B)
{
if(A.r!=B.r) return A.r<B.r;
else return A.l<B.l;
}
int vis[];
int main()
{
int N,i,j,k;
cin>>N;
for(i=;i<=N;++i){
scanf("%d%d",&P[i].l,&P[i].r);
}
sort(P+,P++N,cmp);
int s=;
vector<int>vi;
for(i=;i<=N;++i)
{
if(vi.empty()) {s++;vi.push_back(P[i].r);continue;}
int u=-,w=-,ok=;
for(j=;j<vi.size();++j)
{
if(P[i].l>=vi[j]){
ok=;
if(w<vi[j]){
w=vi[j];
u=j;
}
}
}
if(!ok){s++;vi.push_back(P[i].r);}
else vi[u]=P[i].r;
}
cout<<s<<endl;
return ;
}
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<pair<int,int> >event;
int main()
{
int n;
scanf("%d",&n);
int st,ed;
for(int i=;i<n;i++)
{
scanf("%d%d",&st,&ed);
event.push_back(make_pair(st,));
event.push_back(make_pair(ed,-));
}
sort(event.begin(),event.end());
int cnt=,ans=;
for(int i=;i<event.size();i++)
{
cnt+=event[i].second;
if(ans<cnt)ans=cnt;
}
printf("%d\n",ans);
return ;
}
51nod 1428 贪心的更多相关文章
- 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 1428【贪心】
思路: 就是先排序,然后对每个取最小的结束时间. #include <bits/stdc++.h> using namespace std; typedef long long LL; c ...
- 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 基准时间限制 ...
随机推荐
- 转载:http://blog.csdn.net/foruok/article/details/53500801
凭兴趣求职80%会失败,为什么 标签: 求职跳槽找工作兴趣技术 2016-12-07 06:51 43316人阅读 评论(69) 收藏 举报 本文章已收录于: 分类: 随笔(144) 作者同类文章 ...
- Commit 函数WAIT = 'X'.
BAPI_TRANSACTION_COMMIT IF WAIT EQ SPACE. COMMIT WORK. ELSE. COMMIT WORK AND WAIT. IF SY-SUBRC NE . ...
- 中间件 WSGI
冒泡程序 array = [1, 2, 5, 3, 6, 8, 4] for i in range(len(array) - 1, 0, -1): print i for j in range(0, ...
- SQLServer导入Excel,复杂操作
导入Excel 先导入的时候报错了, 提示未在本地计算机上注册"Microsoft.ACE.Oledb.12.0"提供程序.(System.Data),去网址下个软件安装就搞定了, ...
- JQuery 操作 checkbox 二次赋值无效 attr ----> prop
CheckBox .attr('checked',false); Chrome和火狐第二次点击无效. 然后解决了把attr 改成了 prop 以后操作属性的时候各位记下,用prop 因为大家用的都是 ...
- PL/SQL不能格式化SQL:--PL/SQL Beautifier could not parse text
PL/SQL sql语句美化器点击没有反应.查看下面提示PL/SQL Beautifier could not parse text.本人此次产生的原因是sql语句语法错误. 工具栏处(如果没有此按钮 ...
- php异常处理类
<?php header('content-type:text/html;charset=UTF-8'); // 创建email异常处理类 class emailException extend ...
- Mac 环境 下使用Charles 抓包Http/Https请求
实现目标 在Mac 上 对 iOS 真机 和 模拟器 进行 Http/Https抓包 使用工具 Mac 上 Charles 4.2 安装 参考链接 1. 和 链接 2. 抓包 http 请求 (1 ...
- 【转载】OPENWRT入门之四------openwrt命令行模式命令及其工具
连接来源http://bbs.xiaomi.cn/thread-9734746-1-1.html 需要学会用ssh登录路由器用linux命令查看.ps 命令查看当前系统运行的进程信息free 命令查看 ...
- 老司机也该掌握的MySQL优化指南
当MySQL单表记录数过大时,增删改查性能都会急剧下降,所以我们本文会提供一些优化参考,大家可以参考以下步骤来优化: 除非单表数据未来会一直不断上涨,否则不要一开始就考虑拆分,拆分会带来逻辑.部署.运 ...