one solution is use BFS On Mon, Nov 14, 2011 at 8:52 PM, Anshul AGARWAL <anshul.agarwa...@gmail.com> wrote: > i m try to increase current floor c by push up button until it equal or > greater than "g" and increase co-responding push "p".when my current > floor is greater than "g".i push down button once and increase "p " by 1. > repeat this loop until i get c==g. > Anshul Agarwal > Nit Allahabad > Computer Science > > > > On Mon, Nov 14, 2011 at 9:50 AM, shady <sinv...@gmail.com> wrote: >> >> what;s your algorithm ? >> >> On Mon, Nov 14, 2011 at 7:57 PM, Anshul AGARWAL >> <anshul.agarwa...@gmail.com> wrote: >>> >>> problem is http://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. >> >> -- >> 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. > > -- > 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. >
-- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee -- 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.