2016 Summer vacation Multi-School Union---Windows 10

Source: Internet
Author: User

2016 Summer vacation Multi-school Union---Windows Ten (hdu:5802)

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< Span id= "mathjax-span-15" class= "Mrow" >q   ( Span id= "mathjax-span-20" class= "mn" >0≤ p, Q≤ 109 ) /span> Outputthe minimal seconds He should take sample Input21 3 sample Output44 AUTHORUESTC Source2016 multi-university Train   ing Contest 6 Recommendwange2014 | We have a carefully selected several similar problems for you:5808 5807 5806 5804 5803 Test instructions: There is a radio, volume from the 0~ infinity, there is a volume adjustment and two keys, if the tune Big key, each volume plus one, such as pressing the small key, the first time minus 1, the second minus 2, the third minus 4 ... Multiples increase, can only press once per second key, if the last second no key or the key, this second press is the key, then the volume minus one, to ask from A to b the least time; train of thought: if a<=b, the result is b-a; if the thought of A>b,dfs divide and conquer, reduce the volume as downward as possible; The code is as follows:
#include <iostream>#include<stdio.h>#include<algorithm>using namespaceStd;typedefLong Longll;ll sum[ -];ll ans,a,b;voidinit () {sum[0]=0;  for(LL i=1; i<= -; i++) Sum[i]=(1<<i)-1;} ll Dfs (ll x,ll step,ll stop) {if(x==b)returnStep///x current position, equal to B when exiting the current stack    intk=0;  while(X-SUM[K]&GT;B)//to the K value, the current position is less than or equal to the B position after jumping down the K stepk++; if(x-sum[k]==b)returnStep+k;///just jump to position b .ll up =b-max (LL)0, X-sum[k]);///X-sum[k] The number of steps to jump up and up to 0 positions under B.ll Res=k+max (LL)0, up-stop);///joined the K-step, and then went up, a total of k+up-stop steps///Up-stop, go up without the need to pause, up the number of steps than the pause more use up to replace the pause,    returnMin (Step+res,dfs (x-sum[k-1],step+k,stop+1));///take the smallest one that is now upside down and continues to run down}intMain () {init (); intT; scanf ("%d",&t);  while(t--) {scanf ("%lld%lld",&a,&b); if(a<=b) {printf ("%lld\n", B-a); Continue; }        Elseprintf ("%lld\n", Dfs (A,0,0)); }    return 0;}

2016 Summer vacation Multi-School Union---Windows 10

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.