Windows 10
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 2191 Accepted Submission (s): 665
problem DescriptionLong ago, there was an old monk living on the top of a mountain. Recently, our old monk found the operating system of his computer is updating to Windows automatically and he even can ' t just stop it!!
With a peaceful heart, the old monk gradually accepted this reality because he favorite comic lovelive doesn ' t depend on The OS. Today, like the past day, he opens Bilibili and wants to watch it again. But he observes, the voice of his computer can is represented as DB and always be integer.
Because He is old, and he always needs 1 second to press a button. He found that if he wants to take up the voice, he only can add 1 DB in each second by pressing the UP button. But when he wants the voice, he can press the button, and if the last second he presses the button and the voice decrease X db, then on this second, it'll decrease 2 * x db. If the last second he chooses to has a rest or press the up button, in this second he can only decrease the voice by 1 DB.
Now, he wonders the minimal seconds he should take to adjust the voice from P DB to Q db. Please be careful, because of some strange reasons, the voice of he computer can larger than any dB but can ' t is less tha N 0 DB.
InputFirst line contains a numberT(1≤T≤300000 ), cases number.
Next T Line,each line contains and numbersPand q (0≤p,q≤9)
OutputThe minimal seconds he should take
Sample Input21 57 3
Sample Output44
AUTHORUESTC Source2016 multi-university Training Contest 6 Recommendwange2014
Exercises
First as far as possible to descend and then rise back, or as far as possible to decline and then go down, so you can turn the problem into a sub-problem, and then DFS is good, it is necessary to note that because L can also interrupt the effect of continuous drop, it should be recorded a few times, after the rise of the time with a pause to fill back, Time complexity O (TLOGQ)
#include <bits/stdc++.h>using namespacestd;Const intinf=0x7fffffff; typedefLong Longll;ll Res;intT;Long Longp,q;Long Longsum[ -];voidDfs (ll x,ll y,ll ti,ll stop) {if(x==y) {res=min (Res,ti);return;} intk=1; while(x-sum[k]>y) k++; if(x-sum[k]==y) {res=min (res,ti+k);return;} ll up=q-max (LL)0, X-Sum[k]); Res=min (Res,ti+k+max (LL)0, up-stop));//pauses can be replaced by pressing upDFS (x-sum[k-1],y,ti+k,stop+1);//number of pauses +1, down volume down from 1 onwards return;}intMain () { for(intI=1; i<= to; i++) Sum[i]=(1<<i)-1; scanf ("%d",&T); for(; T>0; t--) {scanf ("%lld%lld",&p,&q); if(p<=q) printf ("%lld\n", Q-p); Else{res=inf; DFS (P,Q,0,0); printf ("%lld\n", RES); } } return 0;}
HDU 5802 Windows Ten (Dfs)