NYOJ14会场安排问题
2016-02-09 13:05
447 查看
#include<stdio.h>
#include<algorithm>
using namespace std;
struct activity
{
int start;
int end;
}a[10000];
bool cmp(struct activity a,struct activity b)
{
if(a.end != b.end) return a.end < b.end;
else return a.start < b.start;
}
int main()
{
int n,c,i,times,end;
scanf("%d",&n);
while(n--)
{
times = 1;
scanf("%d",&c);
for(i = 0;i < c;i++)
{
scanf("%d %d",&a[i].start,&a[i].end);
}
sort(a,a+c,cmp);
end = a[0].end;
for(i = 1;i < c;i++)
{
if(a[i].start > end)
{
times++;
end = a[i].end;
}
}
printf("%d\n",times);
}
return 0;
}
#include<algorithm>
using namespace std;
struct activity
{
int start;
int end;
}a[10000];
bool cmp(struct activity a,struct activity b)
{
if(a.end != b.end) return a.end < b.end;
else return a.start < b.start;
}
int main()
{
int n,c,i,times,end;
scanf("%d",&n);
while(n--)
{
times = 1;
scanf("%d",&c);
for(i = 0;i < c;i++)
{
scanf("%d %d",&a[i].start,&a[i].end);
}
sort(a,a+c,cmp);
end = a[0].end;
for(i = 1;i < c;i++)
{
if(a[i].start > end)
{
times++;
end = a[i].end;
}
}
printf("%d\n",times);
}
return 0;
}
相关文章推荐
- Docker常用命令
- Dockerfile初探
- 【第二章】 IoC 之 2.1 IoC基础 ——跟我学Spring3
- JS产生随机数的几个用法!
- 数据结构: 栈
- scala入门教程:scala中的面向对象定义类,构造函数,继承
- 多线程 (五)NSOperation
- Java中的Copy-On-Write容器
- HDU——1058Humble Numbers(找规律)
- seerThcraeSyraniBeuqinU.96
- 51nod 1275:连续子段的差异 单调队列
- 自发行python版本制作(二)编译
- Objc生成搜索引擎查询字符串
- Objc生成搜索引擎查询字符串
- Objc生成搜索引擎查询字符串
- 系统突然断电重启导致rac节点无法启动,crs-4000错误
- 拓薪教育-struts2视频教程-任亮
- 可重入和线程安全
- 拓薪教育-spring视频下载-任亮
- usaco 1.2.5 dualpal