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 基准时间限制 ...
随机推荐
- vue 基础核心学习
<html> <body> <div id="app"> {{ message }} </div> <div id=" ...
- Python之正则表达式与常用模块(Day19)
一.正则表达式:匹配字符串的一种规则 正则表达式的在线测试工具: http://tool.chinaz.com/regex/ 字符组: 正则 待匹配字符 匹配结果 说明 [0123456789] 8 ...
- This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in问题
点击 Help > Install New Software. 在 Work with 的输入区域里, 输入: https://dl-ssl.google.com/android/eclipse ...
- requirejs源码分析: config中shim
shim处理的源码: //Merge shim if (cfg.shim) { eachProp(cfg.shim, funct ...
- sublime text - vintage
使用sublime text的vim模式的同学注意了: { "color_scheme": "Packages/Color Scheme - Default/Mac Cl ...
- $git学习总结系列(2)——远程仓库
本文主要介绍git本地仓库和GitHub远程仓库之间的交互和数据传输. 注:首先需要到github.com上注册一个账号. 1. 添加本地SSH Key到GitHub 要向GitHub远程仓库推送代码 ...
- Word内容修改,以及转PDF
Word模板内容修改 1.java代码 package com.sicdt.sicsign.web.utils; import java.io.ByteArrayInputStream; import ...
- jQuery滑动杆打分插件
在线演示 本地下载
- photoshop cs5 序列号永久序列号永久激活破解方法
photoshop cs5 序列号永久序列号永久激活破解方法 (2016-12-10 07:52:21) 转载▼ 标签: it PhotoShop CS5 /ps5 序列号激活码 1330-15 ...
- INSPIRED启示录 读书笔记 - 第37章 大众网络服务产品
十大要点 1.可用性:大众网络服务产品必须具备良好的用户体验 2.人物角色:按典型特征将用户分类,抽象出有代表性的用户类型(人物角色) 3.扩展性:应该不间断地考虑扩展性问题,永远留有余地,不到万不得 ...