标签:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct edge{ int b,e; }t[100010]; bool vis[100010]; bool cmp(edge i,edge j){ if(i.b == j.b) return i.e < j.e; return i.b < j.b; } int main() { int M; int x,y; while(~scanf("%d",&M)){ int count = 1; memset(vis,false,sizeof(vis)); while(~scanf("%d%d",&x,&y)){ if(x == 0 && y == 0) break; if(y <= 0 || x >= M || x == y) continue; t[count].b = x; t[count++].e = y; } sort(t+1, t+count,cmp); int end = 0,pos = 1; int flag = 1,res = 0;; while(end < M){ int end1 = 0,npos = 1; while(pos < count && t[pos].b <= end){ if(t[pos].e > end1){ end1 = t[pos].e; npos = pos; } pos++; } if(end1 == 0) {flag = 0 ;break;} end = end1; vis[npos] = 1; res++; } if(flag == 0) printf("No solution\n"); else { printf("%d\n",res); for(int i = 1; i < count ;i++){ if(vis[i]) printf("%d %d\n",t[i].b,t[i].e); } } } return 0; }
URAL1303——贪心——Minimal Coverage
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4495009.html