poj1716Integer Intervals
来源:互联网 发布:真实恐怖故事知乎 编辑:程序博客网 时间:2024/06/06 11:00
题目链接:点击打开链接
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node{
int a,b;
}num[10010];
bool cmp(node x,node y)
{
if(x.b==y.b)
return x.a<y.a;
return x.b<y.b;
}
int main()
{
int n,i,s,u,v;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d%d",&num[i].a,&num[i].b);
sort(num,num+n,cmp);
s=2;
u=num[0].b-1;
v=num[0].b;
for(i=1;i<n;i++)
{
if(u>=num[i].a)
{
if(v>=num[i].a)
continue;
else
{
s++;
v=num[i].b;
}
}
else
{
if(v>=num[i].a)
s++;
else
{
s+=2;
v=num[i].b-1;
}
u=num[i].b;
}
}
printf("%d\n",s);
return 0;
}
0 0
- poj1716Integer Intervals
- Intervals
- Intervals
- Intervals
- Intervals
- Intervals
- 1089 Intervals
- the intervals
- PKU1201 Intervals
- PKU1201 intervals
- poj1201 Intervals
- poj3680 Intervals
- poj1201 - Intervals
- Merge Intervals
- Merge Intervals
- poj_1716Integer Intervals
- Merge Intervals
- Insert Intervals
- 【gulp】JS文件的压缩混淆与雪碧图
- HDU1540Tunnel Warfare(线段树区间合并)
- 排序算法之快速排序
- uboot下init_sequence_f函数之setup_reloc
- Matplotlib直方图和四方图
- poj1716Integer Intervals
- 线程常用的方法
- jQuery Mobile页面加载机制及页面跳转出现的问题
- Spring 查找hibernate映射文件:mappingResources、mappingLocations、mappingDirectoryLocations与mappingJarLocatio
- 游戏开发完整学习路线
- thinkphp表单令牌防止重复提交
- 函数的默认实参
- 使用RecyclerView展示瀑布流的效果
- uboot下init_sequence_f函数之copy_uboot_to_ram