Touch of Venom
Given below c++ code is for venom spoj or touch the venom spoj.
Explanation:-
Let H= Health, P = Poison, A = Heal Value
Let Hero survived for “X” step (here we can see that answer
will be odd position because health decreases on only odd position we will see
this below)
Now writing step from 1
At fifth step you can calculate the relation between “X” and “n” by observing its values.
X= n + n – 1 -> 2n -1
Now at X position we got an equation whose value should be less than or equal to zero.
From above formula we will get value of "n" but actual value will be ceil(n) because we are checking for zero or less then zero.
Our answer will be X = 2n-1
#include <bits/stdc++.h> using namespace std; #define LL long long int main() { int t; scanf("%d",&t); while(t--) { int h,p,a; scanf("%d%d%d",&h,&p,&a); if(h<=p) { printf("1\n"); continue; } double y,z,d; LL result=0; y= p - 2*a; z= 2*(a-h); d= sqrt(y*y - 4*p*z); result = ceil((-1*y + d)/(2*p)); result = result + (result-1); printf("%lld\n",result); } return 0; }
No comments:
Post a Comment
Your comment is valuable to us