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:最简单的代码!!!信不信由你!下面大牛提供的测试数据很给力!在这感谢大牛了! Posted by:chenxuan123456789 at 2012-09-15 22:49:56 #include <stdio.h> #include <stdlib.h> struct cows { int start; int end; }cow[25001]; int cmp(void const *a,void const *b) { return ((struct cows *)a)->start-((struct cows *)b)->start; } int main() { int N=0,T=0; int now=0,i=0,count=0,max=0; char flag=0; while(scanf("%d%d",&N,&T)!=EOF) { for(i=0;i<N;++i) { scanf("%d%d",&cow[i].start,&cow[i].end); } qsort(cow,N,sizeof(struct cows),cmp); for(i=0;i<N&&now<T;++count) { flag=0; while(i<N&&cow[i].start<=now+1) { if(cow[i].end>max) { max=cow[i].end; flag=1; } ++i; } if(!flag) { break; } else { now=max; } } if(now<T) { puts("-1"); } else { printf("%d\n",count); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator