Baby Step, Giant Step

Sort by

recency

|

10 Discussions

|

  • + 0 comments

    Java

    public static int solve(int a, int b, int d) {
      if(d == 0) return 0;
      if(d == b || d == a) return 1;
      if(d < 2 * b) return 2;
      return d/b + (d%b==0?0:1);
    }
    
  • + 0 comments

    include

  • + 0 comments

    int solve(int a, int b, int d) { if(d==0) return 0; else if(d==a || d==b) return 1; else { if((d-b)%b==0) return (d-b)/b+1; else return (d-b)/b+2; } }

  • + 1 comment

    My analysis:-
    given a < b

    Condition # Step(s) Comment
    d == 0 0 no steps
    a == d 1 straight line
    b == d 1 straight line
    a > d 2 Isosceles triangle 2 legs of length a or b
    over base d
    b > d 2 ditto
    a + b > d 2 triangle:- long side of length b
    , other of length a for other side
    over other side d
    r == 0 n n = d/b , r = d % b and straight line if r == 0
    r != 0 n + 1 Triangle of 1 side n*b the other a or b
    = n+1 steps

  • + 1 comment

    Can anyone tell what's wrong with my code ?

    include

    include

    include

    include

    include

    using namespace std;

    long long a,b,d,ans; int main() { int t; cin >> t; while(t--) { ans =0; cin >> a >> b >> d; if(d>0) { if(d==min(a,b)||d==max(a,b)) {cout<<"1\n";continue;} ans = d/max(a,b); if(d%max(a,b)==min(a,b)) { ans++; } else if(d%max(a,b)!=0) ans+=2; } cout< return 0; }