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 |
同样的代码,有时候是ac,有时候wa,什么情况?#include<stdio.h> #include<algorithm> using namespace std; struct node{ int start,end; }cow[25010]; bool cmp(node x,node y){ if(x.start<=y.start) return true; else return false; } int main(){ int n,t,i,count,tail,p,m; scanf("%d%d",&n,&t); for(i=0;i<n;i++) scanf("%d%d",&cow[i].start,&cow[i].end); sort(cow,cow+n,cmp); count=tail=p=0; while(tail!=t){ m=tail; while(cow[p].start<=tail+1){ if(cow[p].end>m) m=cow[p].end; p++; } if(m==tail) break; tail=m; count++; } if(tail!=t) printf("-1\n"); else printf("%d\n",count); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator