Topic Links:
Windows 10
Time limit:2000/1000 MS (java/others)
Memory limit:65536/65536 K (java/others)
Problem Descriptionlong long ago, there is 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 Test Instructions: Q What is the shortest time from p to Q? Train of thought: see other people's only know how to do, each successive descent x times, altogether drops the volume of 2x-1, each descend to be bigger than Q big or the number that is close to Q small, why this? Assume that there are two successive drops of x times. So it can be connected to a x+1 drop, so the number of successive drops in the front is larger than the rear; AC Code:
/************************************************┆┏┓┏┓┆┆┏┛┻━━━┛┻┓┆┆┃┃┆┆┃━┃┆┆┃┳┛┗┳┃┆┆┃┃ ┆┆┃┻┃┆┆┗━┓┏━┛┆┆┃┃┆┆┃┗━━━┓┆┆┃ac Horse ┣┓┆┆┃┏┛┆┆┗┓┓┏━┳┓┏┛┆┆┃┫┫┃┫┫┆ ┆┗┻┛┗┻┛┆************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <cmath>//#include <bits/stdc++.h> #include <stack> #include <map> using namespace std; #define for (i,j,n) for (int i=j;i<=n;i++) #define MST (SS,B) memset (ss,b,sizeof (ss)); typedef long Long LL; Template<class t> void Read (t&num) {char CH; bool F=false; For (Ch=getchar (); ch< ' 0 ' | | Ch> ' 9 '; f= ch== '-', Ch=getchar ()); for (num=0; ch>= ' 0 ' &&ch<= ' 9 '; num=num*10+ch-' 0 ', Ch=getchar ()); F && (num=-num);} int stk[70], tp;template<class t> inline void print (T p) {if (!p) {puts ("0"); return;} while (p) Stk[+ TP] = p%10, p/=10; while (TP) Putchar (stk[tp--] + ' 0 '); Putchar (' \ n ');} Const LL Mod=1e9+7;const double Pi=acos ( -1.0); const ll Inf=1e18;const int N=2e5+10;const int Maxn=2e3+14;const double eps= 1e-12; ll Ans,f[40];void Dfs (ll p,ll q,ll time,int num) {if (max (P,0LL) ==q) {ans=min (ans,time); return; } else if (max (P,0LL) <q) {LL Temp=q-max (0ll,p); Ans=min (Ans,time+max (TEMP-NUM,0LL)); return; } int l=1; while (P (f[l]-1) >q) l++; DFS (P (f[l]-1), q,time+l,num); if (l>1) DFS (P (f[l-1]-1), q,time+l,num+1);} inline void Solve (LL p,ll q) {ans=inf; DFS (p,q,0,0); printf ("%lld\n", ans);} inline void Init () {f[0]=1; for (i,1,35) f[i]=f[i-1]*2;} int main () {int t; LL p,q; Read (t); Init (); while (t--) {read (P); Read (q); Solve (P,Q); } return 0;}
hdu-5802 Windows 10 (greedy)