hdu5802

来源:互联网 发布:mac手游模拟器电脑版 编辑:程序博客网 时间:2024/05/22 07:54

说实话,比赛没过,真的是这个题的题意太水!!!!码的以为是操作过程中不能降到0以下!!!我擦,题解出来居然是默认到0以下就归0了!!!!靠,知道题意一发就过了!!靠了,什么鬼都

Windows 10

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 632    Accepted Submission(s): 180


Problem Description
Long long ago, there was an old monk living on the top of a mountain. Recently, our old monk found the operating system of his computer was updating to windows 10 automatically and he even can't just stop it !!
With a peaceful heart, the old monk gradually accepted this reality because his 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 that the voice of his computer can be represented as dB and always be integer.
Because he is old, 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 to take down the voice, he can press the down button, and if the last second he presses the down button and the voice decrease x dB, then in this second, it will decrease 2 * x dB. But if the last second he chooses to have 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 his computer can larger than any dB but can't be less than 0 dB.
 

Input
First line contains a number T (1T300000),cases number.
Next T line,each line contains two numbers p and q(0p,q109)
 

Output
The minimal seconds he should take
 

Sample Input
21 57 3
 

Sample Output
44
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <iomanip>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>#include <list>#include <map>#include <set>#define ULL unsigned long long#define PI 3.1415926535#define INF 2147483647#define LL long long#define eps 1e-8using namespace std;int solve(int x,int y,int step,int stop){    if(x==y)    return step;    int temp=0;    while(x-(1<<temp)+1>y)    {        temp++;    }    if(x-(1<<temp)+1==y)        return temp+step;//下面说的上面是这里    int up=y-max(x-(1<<temp)+1,0);//如果降到了y下面,要先往上几步来走    int ans=temp+max(0,up-stop);//把要往上走的步数用停顿来抵消!!    return min(ans+step,solve(x-(1<<(temp-1))+1,y,step+temp,stop+1));}int main(){    int t;    int p, q;    scanf("%d", &t);    while(t--)    {        scanf("%d%d", &p, &q);        if(p <= q)            printf("%d\n", q - p);        else        {            int ans=solve(p,q,0,0);            printf("%d\n",ans);        }    }    return 0;}


0 0
原创粉丝点击