会场安排问题 nyoj

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,ans;
struct node{
	int B,E;
}a[10001];
/*超时
int book[1001];
void dfs(int t,int count,int end);
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&m);
		for(int i=0;i<m;i++){
			scanf("%d%d",&a[i].B,&a[i].E);		
		}
		memset(book,0,sizeof(0));
		dfs(0,0,0);
		cout<<ans<<endl;
	}
	return 0;
} 
void dfs(int t,int count,int end){
	if(ans<count){
		ans=count;
	}
	if(t>=m){
		return ;
	}
	for(int i=t;i<m;i++){
		if(a[i].B>=(end+1)&&(!book[i])){
			book[i]=1;
			dfs(i+1,count+1,a[i].E);
			book[i]=0;
		}
	}
	return ;
}
*/
int com(struct node a,struct node b){
	return a.E<b.E;
}
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&m);
		ans=0;
		for(int i=0;i<m;i++){
			scanf("%d%d",&a[i].B,&a[i].E);		
		}
		sort(a,a+m,com);
		int time=0;
		for(int i=0;i<m;i++){
			if(time<a[i].B){
				ans++;
				time=a[i].E;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
} //解决问题的关键:优先选择结束时间早的活动。
//开始时间早,活动时长段...安排活动的重点时结束时间早!!! 

猜你喜欢

转载自blog.csdn.net/chan_yeol/article/details/52415239
今日推荐