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 |
哪位大牛帮忙看下,(内附代码),为什么老WA啊,郁闷,纠结!!#include<stdio.h> int main() { long N,T,i,begin,end; scanf("%d%d",&N,&T); long *a=new long[T+1]; for(i=0;i<=T;i++) a[i]=0; for(i=1;i<=N;i++) { scanf("%d%d",&begin,&end); if(end>a[begin]) a[begin]=end; } long count=0,max=0,index; begin=1; end=0; while(end!=T) { ++count; end=a[begin]; max=a[begin]; index=begin; for(i=end;i>begin&&end!=T;i--) if(a[i]>max) { max=a[i]; index=i; } if(a[index]==end) break; begin=index; printf("end=%d\n",end); } if(end!=T) printf("%d\n",-1); 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