Saturday, 26 March 2016

Solution of LIGHT OJ 1069 :: Lift


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b,c,d,e,f;
    scanf("%d", &c);
    for(d=1; d<=c; d++)
    {
        scanf("%d%d", &a, &b);
        if(a<=b)
            e=b*4+19;
        else
            e=(2*a-b)*4 +19;
        printf("Case %d: %d\n", d,e);
    }
    return 0;
}

3 comments:

  1. why do we have to give the condition e=(2*a-b)*4+19

    ReplyDelete
  2. I m also not understand this logic

    ReplyDelete
    Replies
    1. 'a' is your position
      'b' is lift position
      '2*a' is twice your position or ground to you & you to ground
      '2*a-b' is total floor left need to travel
      '*4' is time for each floor
      '19' is total time for open+entry+close++open+exit.

      Delete

Note: only a member of this blog may post a comment.