NYOJ-14 会场安排问题(贪心 区间覆盖)

#include
#include
#include
#include
#define MAX 10000+1
#define IN 100000
using namespace std;

struct node{
	int left,right;
};

bool cmp_right(struct node a, struct node b){
	return a.right>T;
	while(T--){
		cin>>n;
		for(int i=0;i>a[i].left>>a[i].right;
		}
	    sort(a,a+n,cmp_right);

	    now_len=0;
	    count=0;
	    flag=1;
	    int k=0;
	    while(1){
	    	min=IN;
	    	for(int j=0;jnow_len){
	    		if((a[j].right-now_len)< min) {
	    			min=a[j].right-now_len;
				}
			}
			}
			if(min==IN){
				break;
			}
			else{
				count++;
				now_len+=min;
			}
		}
		cout<
千万不要写成for(int j=0;jnow_len;j++) 因为for循环的第二部分不满足的话就直接退出循环而不是j自增再循环一遍,被坑了好久

你可能感兴趣的:(acm_基础算法)