您的位置:首页 > 其它

nyoj 14 会场安排问题

2012-08-21 20:31 141 查看
http://acm.nyist.net/JudgeOnline/problem.php?pid=14

选择不相交的区间,不过这道题数有点大。。。我好几次超时。。看了网上的一些改了很多。。呃。。都快改的和人家一样了。。。主要是用了一个数据结构struct和algorithm。。。否则超时,因为algorithm用的是快速排序,效率很高!

#include <cstring>
#include <cstdio> 
#include <algorithm>
using namespace std;
struct node
{
	int s;
	int e;
}a[10010];
bool cmp(node p,node q){
	return p.e<q.e;
}
int main()
{
	int m;
	scanf("%d",&m);
	while(m--){
		int n,num=0;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
			scanf("%d%d",&a[i].s,&a[i].e);
		sort(a,a+n,cmp);
		if(n==0){
			printf("0\n");
			continue;
		}
		int flag=0;
		num=1;
		for(int i=1;i<n;i++){
			if(a[i].s>a[flag].e){
				num++;
				flag=i;
			}
		}
		printf("%d\n",num);
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: