Test instructions
Give a number x.
The starting point is the coordinate 0. 1th Step Jump 1 grid, 2nd step Jump 2, 3rd step jump 3 grid, ... And so on
You can jump to the left or right at a time.
Ask at least jump a few steps to coordinate x.
Ideas:
Suppose X is a positive number.
The quickest way to approximate x is to keep going to the right. If X is crossed, the X1 is assumed to be x1-x less than the last step d.
If X1-x is an even number, change the previous x to-X. Then you can go to X.
If X1-x is an odd number, because the previous x is changed to-X, it is actually back 2x. So you must take one more step to the right. Until X1-x is an even number. (In fact, just one or two steps)
X is negative and the x is positive.
Code:
ll X,d;intMain () {CIN>>x; if(x==0) {puts ("0"); return 0; } if(x<0) {x=-x; } d=1; while(D* (d+1)/2<X) + +D; if(D* (d+1)/2==x) {printf ("%i64d\n", D); } Else{ll x1=d* (d+1)/2; ll Deta=x1-x; if(deta%2==0) {printf ("%i64d\n", D); } Else{ while(deta%2!=0){ ++D; X1+=D; Deta=x1-x; } printf ("%i64d\n", D); } } return 0;}
CF 11B jumping Jack (greedy, mathematical proof,,)