Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
能否帮忙看看?In Reply To:我按左端点升序排列,然后贪心 可是WA了 Posted by:joyo at 2005-10-02 21:37:36 //n 线段个数 //每次找能覆盖的且右端点最大的 founded=0; i=0; t=0; cnt=0; while(!founded&&i<n){ for(j=-1,max=t;i<n&&line[i].l<=t;i++){ if(line[i].r>max){ max=line[i].r; j=i; } } if(j!=-1){ ans[cnt++]=j; if(max>=m){ founded=1; } t=max; } else break; } //输出 if(!founded) printf("No solution\n"); else{ printf("%d\n",cnt); for(i=0;i<cnt;i++){ printf("%d %d",line[ans[i]].l,line[ans[i]].r); } printf("\n"); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator