We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Baby Step, Giant Step
Baby Step, Giant Step
Sort by
recency
|
10 Discussions
|
Please Login in order to post a comment
Java
include
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; } }
My analysis:-
given a < b
over base d
, other of length a for other side
over other side d
= n+1 steps
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; }