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 |
Re:贴个代码,过了但是我觉得有问题,各位大神有空看下In Reply To:贴个代码,过了但是我觉得有问题,各位大神有空看下 Posted by:529127 at 2015-06-02 16:41:50 > #include <iostream> > #include<map> > #include<string> > #include<memory.h> > #include<math.h> > #include<stdio.h> > #include<algorithm> > using namespace std; > int n,t; > > struct st{ > int a,b; > }que[25005]; > bool sort1( st x,st y){ > > return x.a<y.a; > > } > int main() > { > //freopen("in.txt","r",stdin); > scanf("%d%d",&n,&t); > int i,j; > for(i=1;i<=n;i++) > scanf("%d%d",&que[i].a,&que[i].b); > > sort(que+1,que+n+1,sort1); > int num=0,data1=1,data2=0; > if(que[1].a>1) > cout<<-1<<endl; > else{ > > data2=data1=0; > j=1,i=1; > int fg; > for(;j<=n;){ > fg=0; > for(;i<=n;i++){ > if(que[i].a<=data1+1) > {fg=1; > if(que[i].b>data2) > data2=que[i].b,j=i; > } > else > break; > } > if(fg==0) > break; > data1=que[j].b; > num++; > //cout<<que[j].b; > > if(data2>=t) > break; > } > if(que[j].b>=t&&fg==1) > cout<<num<<endl; > else > cout<<-1<<endl; > } > > > return 0; > > } > 这个所设置的fg完全没意义啊,应该把fg放在 if(que[i].b>data2)下一级才对吧, > 放这个位置会导致不连续的情况出现 > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator