Uarl 1303

PRO IS HERE


其实只是简单的贪心即可,按(x,y) 排序,然后尽量取y大的。。。


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<map>
using namespace std;

#define PB push_back
#define INS insert
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define nMax 101000
#define bug puts("Fuck");

int m,n;
vector<int> ans;
struct BB{
	int x,y,xx,yy;
	bool read(int &n){
		scanf("%d%d",&xx,&yy);
		if(xx == 0 && yy == 0) return false;
		if(yy<0 || xx>m) ;
		else n++;
		x = xx,y=yy;
		if(x<0) x = 0;
		if(y>m) y = m;
		return true;
	}
	bool operator < (const BB & b) const {
		if(x == b.x) return y < b.y;
		return x < b.x;
	}
};

BB a[nMax];

int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);

	while(~scanf("%d",&m)){
		n = 0;
		while(a[n].read(n));
		sort(a,a+n);
		//printf("n=%d\n",n);
		int l=0;
		ans.clear();
		for(int i=0;i<n;){
			if(l < a[i].x) break;
			int cp=-1,np;
			while(l >= a[i].x && i < n){
			    if(a[i].y > cp) cp=a[i].y,np=i;
                i++;
			}
			if(cp <= l) continue;
			ans.PB(np);
			l = cp;
		}
		if(l < m) printf("No solution\n");
		else {
			printf("%d\n",(int)ans.size());
			for(int i=0;i<ans.size();i++) {
				printf("%d %d\n",a[ans[i]].xx,a[ans[i]].yy);
			}
		}
	}

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值