hdu 5802 Windows 10 (dfs)

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 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 (1≤T≤300000),cases number.
Next T line,each line contains two numbers p and q (0≤p,q≤109)

Output

The minimal seconds he should take

Sample Input

2
1 5
7 3

Sample Output

4
4

Author

UESTC

Source

2016 Multi-University Training Contest 6

Recommend

wange2014

题解:

先尽可能往下降然后升回来,或者尽可能往下降后停然后再往下降,于是就能将问题变成一个子问题,然后dfs就好,需要注意的是由于升也可以打断连续降的功效,所以应该记录停顿了几次,以后上升的时候先用停顿补回来,不够再接着升,时间复杂度O(Tlogq)

#include <bits/stdc++.h>

using namespace std;
const int inf=0x7fffffff;
typedef long long ll;
ll res;
int T;
long long p,q;
long long sum[50];

void dfs(ll x,ll y,ll ti,ll stop)
{
   if (x==y) {res=min(res,ti); return;}

   int k=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)); //停顿可以替换向上按
   dfs(x-sum[k-1],y,ti+k,stop+1); //停顿次数+1,向下减音量从1开始
   return;
}
int main()
{

    for(int i=1;i<=31;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;
}
时间: 2024-08-02 01:10:23

hdu 5802 Windows 10 (dfs)的相关文章

hdu 5802 Windows 10(2016 Multi-University Training Contest 6——贪心+dfs)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5802 Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1005    Accepted Submission(s): 333 Problem Description Long long ago, there was a

hdu 5802 Windows 10

官方题解: Windows 10 _您可能是正版Windows 10的受害者_ 直接贪心就好 比较直观的看法是使劲往下降,然后升回来 或者使劲往下降然后停顿然后再使劲往下降... 于是就能将问题变成一个子问题,然后dfs就好 需要注意的是由于按up键也可以打断连续向下的功效 所以应该记录停顿了几次,以后向上的时候用停顿补回来 /*by*/ #include <iostream> #include <algorithm> #include <cstdio> #includ

hdu5802 Windows 10 贪心

Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2096    Accepted Submission(s): 630 Problem Description Long long ago, there was an old monk living on the top of a mountain. Recently,

2016暑假多校联合---Windows 10

2016暑假多校联合---Windows 10(HDU:5802) 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 j

hdu 1518 Square (dfs搜索可参考poj1011)

Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8589    Accepted Submission(s): 2784 Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end

hdu-5802 Windows 10(贪心)

题目链接: Windows 10 Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) 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 c

Install Hyper-V on Windows 10

? Enable Hyper-V to create virtual machines on Windows 10.Hyper-V can be enabled in many ways including using the Windows 10 control panel, PowerShell (my favorite) or using the Deployment Imaging Servicing and Management tool (DISM). This documents

Windows 10 UWP程序标题栏设置

原文:Windows 10 UWP程序标题栏设置 在Windows 10程序中,以前只能用于全屏方式的Metro程序现在可以运行在窗口模式下了,并且改了个新名字,叫Windows 通用程序(Universal Windows app),简称UWP程序.新的UWP程序虽然大体上还是和以前的Metro程序差不多的,但还是引入了一点新东西的,本文这里就介绍一下它的标题栏设置的几个特性. 隐藏标题栏: 将应用界面扩展至 Titlebar 区域 CoreApplication.GetCurrentView

How to enable C development in a Windows 10 development environment VM

To enable C development in a Windows 10 development environment VM, follow these steps: Start VS in the Windows 10 development environment VM. Choose "File" -> "New" -> "Project", choose "Open Visual Studio Install