学校网站建设工作目标,附近的网站电脑培训班,wordpress 后台 500,网站建设商务题干#xff1a;#xff08;Uva题不给题干了#xff09; t组样例#xff0c;每组首先给出一个M#xff0c;然后给出一些线段#xff08;0 0结束#xff09;#xff0c;然后问怎么取能使得最少的线段覆盖区间[0, M]。
Sample Input 2 1 -1 0 -5 -3 2 5 0 0 1 -1 0 0 1 …题干Uva题不给题干了 t组样例每组首先给出一个M然后给出一些线段0 0结束然后问怎么取能使得最少的线段覆盖区间[0, M]。
Sample Input 2 1 -1 0 -5 -3 2 5 0 0 1 -1 0 0 1 0 0 Sample Output 0 1 0 1
解题报告 就是个贪心啊
AC代码
#includecstdio
#includeiostream
#includealgorithm
#includequeue
#includemap
#includevector
#includeset
#includestring
#includecmath
#includecstring
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX 2e5 5;
struct Node {int st,ed;Node(){}Node(int st,int ed):st(st),ed(ed){}bool operator(const Node b) const{if(st ! b.st) return st b.st;return ed b.ed;}
} node[MAX];
int tot,n,m,cnt,nb;
int ans[MAX];
int main()
{int t;int a,b,maxx,minn;cint;while(t--) {totcnt0;maxx 0,minn 0x3f3f3f3f;scanf(%d,m);while(scanf(%d%d,a,b)) {if(a0 b0) break;if(b0) continue;if(am) continue;node[tot] Node(a,b);maxx max(maxx,b);minn min(minn,a);}sort(node1,nodetot1);int cure,curs;curscure0;
// if(minn m || maxx 0) {
// puts(0);
// if(t) puts();
// continue;
// }int flag 0;for(int i 1; itot; ) {if(node[i].st curs) {break; }while(itot node[i].stcurs) {if(node[i].ed cure) {cure node[i].ed;nb i;}i;}//if(i!tot) i--;ans[cnt] nb;curs cure;if(curs m) {flag1;break;}}if(flag 0) puts(0);else {printf(%d\n,cnt);for(int i 1; icnt; i) printf(%d %d\n,node[ans[i]].st,node[ans[i]].ed);}if(t) puts();}return 0 ;}
总结 那两句读数据的时候的if去掉好像也可以AC反正注释掉的那一部分加上也可以AC。。