hrbust/哈理工oj 1877 区间【水题】
2016-04-30 15:04
465 查看
区间 | ||||||
| ||||||
Description | ||||||
给你一些左闭右开的区间,有交集的区间可划分到一个集合。现在将所有区间划分为尽量少的集合。求最少的集合数。 | ||||||
Input | ||||||
第一行是一个整数T代表测试数据组数 对于每组测试数据第一行是一个整数N(1<=N<=100000)代表区间个数。 接下来N行每行输入两个整数s,t代表[s,t)(0<=s<t<=2^31-1)。 | ||||||
Output | ||||||
对于每组测试数据,输出最少的集合数。 | ||||||
Sample Input | ||||||
3 4 0 1 1 2 2 3 3 4 4 0 2 1 3 2 4 3 5 4 0 4 1 5 2 4 3 6 | ||||||
Sample Output | ||||||
4 2 1 | ||||||
Author | ||||||
陈禹 |
AC代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct zuobiao
{
int x,y;
}a[100002];
int cmp(zuobiao a,zuobiao b)
{
if(a.y!=b.y)return a.y<b.y;
else return a.x<b.x;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
}
sort(a,a+n,cmp);
int yy;
int output=1;
for(int i=0;i<n;i++)
{
//printf("%d %d\n",a[i].x,a[i].y);
if(i==0)
{
yy=a[i].y;
}
else
{
if(a[i].x>=yy)
{
yy=a[i].y;
output++;
}
}
}
printf("%d\n",output);
}
}
相关文章推荐
- 文科状元转CS
- 数据结构相同情况下数据表之间数据的快速"copy"
- maven学习系列3----仓库
- Java注解(二) 系统注解
- 将文件中字符串赋值到ArrayList中
- 关于Wireshark无法启动 一直在加载 loading configrue 或者 initializing解决
- IClient for js开发之地图的加载
- 满满的干货:推荐提升 Android 性能的建议
- OpenJDK Runtime Environment (IcedTea6 1.13.10) (rhel-1.13.10.0.el6_7-x86_64) OpenJDK 64-Bit Server V
- 把ArrayList集合中的字符串内容写到文本文件中
- C++数据结构
- Opencv学习笔记:搭建opencv2.4.9+openGL+QT5.6+vs2013
- C++走向远洋——40(第九周,深复制体验)
- dede织梦调用顶级二级栏目及下三级栏目方法(数据库实现)
- 复制图片的四种方式
- 初学js插入节点appendChild insertBefore使用方法
- 《Linux内核分析》学习总结与学习心得
- DDWF_NOTES_5
- 文件复制的5中方式
- Unity3D占用内存太大的解决方法