其实只是简单的贪心即可,按(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;
}

756

被折叠的 条评论
为什么被折叠?



