codevs 1643 线段覆盖 3
在一个数轴上有n条线段,现要选取其中k条线段使得这k条线段两两没有重合部分(端点可以重合),问最大的k为多少。
输入格式
输入文件的第1行为一个正整数n,下面n行每行2个数字ai,bi,描述每条线段。
输出格式
输出文件仅包括1个整数,为k的最大值
3
0 2
2 4
1 3
2
数据范围
对于20%的数据,n≤10;
对于50%的数据,n≤1000;
对于70%的数据,n≤100000;
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
pair<int,int>p[];
typedef pair<int, int> pi; bool cmp(pi a,pi b)
{
if(a.second<b.second)return ;
else return ; } int main()
{
int n;
scanf("%d",&n);
int x;
int a,b;
for(int i=;i<=n;i++)
{
scanf("%d%d",&a,&b);
if(a>b)swap(a,b);
p[i].first=a;p[i].second=b;
}
sort(p+,p+n+,cmp);
int maxn=-,ans=;
for(int i=;i<=n;i++)
{
if(p[i].first>=maxn)
{
ans++;maxn=p[i].second;
} }
cout<<ans;
}
/*10
1 10
9 20
19 30
29 40
39 50
49 60
59 70
69 80
79 90
89 100*/
对于100%的数据,n≤1000000,0≤ai<bi≤1000000。
codevs 1643 线段覆盖 3的更多相关文章
- codevs 1214 线段覆盖/1643 线段覆盖 3
1214 线段覆盖/1214 线段覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定x轴上的N(0< ...
- codevs 3012 线段覆盖 4 & 3037 线段覆盖 5
3037 线段覆盖 5 时间限制: 3 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 数轴上有n条线段,线段的两端都 ...
- codevs 1214 线段覆盖
1214 线段覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定x轴上的N(0<N<100)条线段,每个线段 ...
- CODEVS 3027 线段覆盖2
首先,先看题.....(虽然比较简单 3027 线段覆盖 2 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 数轴上有n条线段,线段的两端都是整数坐标,坐 ...
- codevs 3027线段覆盖2
传送门 3027 线段覆盖 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 数轴上有n条线段,线段的两端都是整数坐标, ...
- codevs 3012 线段覆盖4
传送门 3012 线段覆盖 4 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 黄金 Gold 题目描述 Description 数轴上有n条线段,线段的两端都是整数坐标,坐 ...
- codevs 1214线段覆盖
1214 线段覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定x轴上的N(0<N<100)条线段,每 ...
- Codevs 3012 线段覆盖 4
3012 线段覆盖 4 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 黄金 Gold 题目描述 Description 数轴上有n条线段,线段的两端都是整数坐标,坐标范围在0~100 ...
- codevs——T1214 线段覆盖
http://codevs.cn/problem/1214/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descr ...
随机推荐
- Angular白名单&&Angular拦截器 全局通用
//angular 白名单全局通用 app.config([ '$compileProvider', function ($compileProvider) { $compileProvider.aH ...
- E. Sonya and Ice Cream(开拓思维)
E. Sonya and Ice Cream time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- es6+最佳入门实践(12)
12.class基础用法和继承 12.1.class基础语法 在es5中,面向对象我们通常写成这样 function Person(name,age) { this.name = name; this ...
- Eclipse工具栏太多,自定义工具栏,去掉调试
Window --> Customize Perspective... --> Tool Bar Visibility 去掉勾选debug Tip:最新版本Customize Persp ...
- [POJ3237]Tree解题报告|树链剖分|边剖
关于边剖 之前做的大多是点剖,其实转换到边剖非常简单. 我的做法是每个点的点权记录其到父亲节点的边的边权. 只要solve的时候不要把最上面的点记录在内就可以了. Tree Description Y ...
- bzoj1008 矩乘递推
2013-11-17 10:38 原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1008 比较水的题,直接矩阵乘法+递推就OK了 w[i,0 ...
- certbot 免费httos证书申请
https://keelii.com/2016/06/12/free-https-cert-lets-encrypt-apply-install/
- pandas 读写sql数据库
如何从数据库中读取数据到DataFrame中? 使用pandas.io.sql模块中的sql.read_sql_query(sql_str,conn)和sql.read_sql_table(table ...
- maven修改本地仓库默认路径问题
找到maven本地路径的settings.xml文件,如D:\Program Files\apache-maven-3.0.5\conf\settings.xml: 在settings.xml文件中增 ...
- vue+axios下载文件的实现
HTML代码: <el-button size="medium" @click="download">下载表格</el-button> ...