hi don i have now implemented it with bfs but it's still giving wrong answer can you please tell the test case #include<stdio.h> int a[1000100][2]; int visited[1000100],i,q[1000100]; int main() { int f,s,g,u,d; scanf("%d%d%d%d%d",&f,&s,&g,&u,&d);
for( i = 1 ; i <= f;i++) { if(i + u > f) { a[i][0] = i; } else { a[i][0] = i + u; } if( i - d < 1) { a[i][1] = i; } else { a[i][1] = i - d; } visited[i] = 0; } /*for( i = 1 ;i <= f; i++) { printf("%d %d %d\n",i,a[i][0],a[i][1]); }*/ int front ,rear; front = 0; rear = 0; q[0] = s; visited[s] = 1; front = 0; int count = 0,flag = 0; int p = 0; while(front <= rear) { int h ; /*for( h = front ;h<= rear ;h++) { printf("%d ",q[h]); }*/ if(!visited[a[q[front]][0]]) { if(a[q[front]][0] == g) { flag = 1; count++; break; } p = 1; q[++rear] = a[q[front]][0]; visited[a[q[front]][0]] = 1; } if(!visited[a[q[front]][1]]) { if(a[q[front]][1] == g) { flag = 1; count++; break; } p = 1; q[++rear] = a[q[front]][1]; visited[a[q[front]][1]] = 1; } if( p == 1) count++; p = 0; front++; /*printf("\n"); scanf("%d",&h);*/ } if(flag == 0) { printf("use the stairs\n"); } else { printf("%d\n",count); } return 0; } On Wed, Nov 16, 2011 at 4:06 AM, Don <dondod...@gmail.com> wrote: > This input > > 100 1 5 5 91 > > Should output 20. Yours says "Take the stairs". > > 100 1 5 5 89 > > Should output 76. Yours says "Take the stairs." > > Don > > On Nov 14, 8:27 am, Anshul AGARWAL <anshul.agarwa...@gmail.com> wrote: > > problem ishttp://www.spoj.pl/problems/ELEVTRBL/ > > and my solution is give wrong answer on spoj . Plz help me to find in > which > > case my solution give wrong answer. > > > > * > > #include<iostream> > > ** > > #include<stdio.h> > > using namespace std; > > int main() > > { > > long long int f,s,u,d,g,c,p; > > > > scanf("%lld%lld%lld%lld%lld",&f,&s,&g,&u,&d); > > > > p=0; > > > > if(s==g) > > printf("0\n"); > > if(s>g&&u==0&&d!=0) > > { > > int temp=s-g; > > if((temp/d)*d==temp) > > { > > p=temp/d; > > printf("%lld\n",p); > > > > } > > else > > printf("use the stairs\n"); > > > > } > > else if(s>g) > > { > > int temp =s; > > s=g; > > g=temp; > > > > // cout<<"2"<<endl; > > } > > //cout<<"1"<<endl; > > c=s; > > if(s<g) > > { while(1) > > { > > int temp=g-c; > > int q; > > if(u==0) > > { > > if(c==g) > > { > > printf("0\n"); > > break; > > } > > else > > { > > printf("use the stairs\n"); > > break; > > } > > } > > if(temp/u==(temp/u)*u) > > { > > q=temp/u; > > > > } > > else > > q=temp/u+1; > > > > if((c+q*u)<=f) > > { // cout<<"1"<<endl; > > p=p+q; > > c=(q)*u+c; > > //cout<<c<<endl; > > } > > else > > {//cout<<"2"<<endl; > > p=p+temp/u; > > c=(temp/u)*u+c; > > } > > if(c==g) > > { > > // cout<<"3"<<endl; > > printf("%lld",p); > > break; > > } > > if(u==d||d==0||((u%d==0)&&d!=0)||(d%u==0&&u!=0)) > > { > > > > printf("use the stairs\n"); > > break;} > > if(c-d>=0) > > { // cout<<"4"<<endl; > > c=c-d; > > p+=1; > > // cout<<c<<endl; > > } > > else > > { > > // cout<<"5"<<endl; > > printf("use the stairs\n"); > > break; > > } > > } > > } > > > > } > > > > Anshul Agarwal > > Nit Allahabad > > Computer Science** > > * > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.