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 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

题目大意:

把音量从p调到q,两种情况:

若p>=q,一直按着每次音量上升1。

若p<q,每次按着的那一秒下降1,接下来一秒下降2,4,8....(2x),x是前一秒下降的值。中途可以选择按键停止或up上升。

解题思路:

两种情况,一种是一直下降,下降到不能下降在上升,另一种是一直下降然后停止在下降。

(需要注意的是由于按up键也可以打断连续向下的功效。所以应该记录停顿了几次,以后向上的时候用停顿补回来)

详见代码。

#include <iostream>
#include <cstdio>

using namespace std;

#define INF 0x3f3f3f3f

int s[32],ans;

void dfs(int n,int t,int time)//有多少要减掉 休息几次 花了多少时间
{
    if (n==0)
        return ;
    int k=lower_bound(s,s+32,n)-s;//在sum中找到第一个比n(要减掉的数)大的数的下标
    int up=s[k]-n;//要向上加多少

    /*这里是不休息的,用向上抵掉一部分休息的*/
    ans=min(ans,time+k+max(up,t));

    /*下面是休息的*/
    if (up)
        dfs(n-s[k-1],t+1,time+k-1);
}

int main()
{
    s[0]=0;
    for (int i=1;i<32;i++)
    {
        s[i]=2*s[i-1]+1;
    }
    int t,p,q;
    scanf("%d",&t);
    while (t--)
    {
        scanf ("%d%d",&p,&q);
        if (p<=q)
            ans=q-p;
        else
        {
            ans=INF;
            dfs(p-q,0,0);
        }
        int i;
        for (i=1;i<32;i++)
        {
            if (s[i]>=p)
                break;
        }
        ans=min(ans,i+q);
        printf ("%d\n",ans);
    }
    return 0;
}
时间: 2024-10-12 19:54:33

hdu 5802 Windows 10(2016 Multi-University Training Contest 6——贪心+dfs)的相关文章

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,

hdu 5802 Windows 10

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

hdu 5821 Ball(2016 Multi-University Training Contest 8——贪心+排序)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5821 Ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 515    Accepted Submission(s): 309 Problem Description ZZX has a sequence of boxes numbe

HDU 6049 - Sdjpx Is Happy | 2017 Multi-University Training Contest 2

思路来源于 FXXL - - 一个比较奇怪的地方就是第三步可以不做,也就是ans至少为1,听说场内有提问的,然后 admin 说可以不做- - (wa的我心烦) /* HDU 6049 - Sdjpx Is Happy [ 枚举,剪枝 ] | 2017 Multi-University Training Contest 2 题意: 长度为N的排列 N <= 3000 排序分三个步骤: 1.原数组分为不相交的K段 2.每段都独立排序 3.选择其中两段swap 问按步骤能成功排序的K能取到的最大是多

windows 10 2016 企业版 长期服务 激活方式

试了很多,失败. 使用这个ok-------------------------------- 使用方式: 2.1.下载AAct.exe https://www.baidu.com/link?url=qZvXvBNmHcW35uDCfEEb4ZYI3fu2ESv08uL7Js-Zlg8nfNrBbdUU1BTtTKY9PXbM&wd=&eqid=9b79e1db00015540000000065aa15577: 2.2.右击AAct.exe,以管理员身份运行: 2.3.点击中下位置的设置按

HDU - 6386 Age of Moyu 2018 Multi-University Training Contest 7 (Dijkstra变型)

题意:N个点M条边的无向图,每条边都有属于自己的编号,如果一条路径上的边编号都相同,那么花费仅为1:改变至不同编号的路径,花费加1,无论这个编号之前是否走过. 分析:记录每个点的最小花费,再用set维护这个最小花费对应的前驱边的编号,可能有多个不同的前驱编号.如果当前状态可以更新点最小花费,那么将set清空并加入前驱编号:如果与最小花费相等且前驱的编号不在集合中,那么将前驱的状态加入集合中. *BFS要用优先队列,否则会错. #include<bits/stdc++.h> using name

Windows 10 Enterprise 2016 LTSB简体中文版

文件名:cn_windows_10_enterprise_2016_ltsb_x86_dvd_9057089.iso (2.62GB) 语言: Chinese – SimplifiedSHA1:0422052F25C9C8DF983F3B287F725860AAB907CF ed2k://|file|cn_windows_10_enterprise_2016_ltsb_x86_dvd_9057089.iso|2817034240|67C3865D03E765BDD4845BA2CB7649F8|

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 5775 Bubble Sort(2016 Multi-University Training Contest 4——树状数组)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5775 Bubble Sort Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 636    Accepted Submission(s): 378 Problem Description P is a permutation of the