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 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   |   We have carefully selected several similar problems for you:  5808 5807 5806 5804 5803

题意:有一个收音机,音量从0~无穷大,有音量调大和调小两个键,若按调大键,每次音量加一,如按调小键,第一次减1,第二次减2,第三次减4……倍数增长,每秒只能按一次键,若上一秒没按键或者是调大键,这一秒按的是调小键,则音量减一,求从a调到b的最少的时间;

思路:若a<=b,则结果就是b-a;若a>b,dfs分治的思想,每次尽可能向下减音量;

代码如下:

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
ll sum[50];
ll ans,a,b;
void init()
{
    sum[0]=0;
    for(ll i=1; i<=33; i++)
        sum[i]=(1<<i)-1;
}

ll dfs(ll x,ll step,ll stop)
{
    if(x==b)return step; ///x 当前位置,等于b 时退出当前栈
    int k=0;
    while(x-sum[k]>b)    //到k值,向下跳k步后  使得当前位置小于等于b位置
        k++;
    if(x-sum[k]==b)
        return step+k;   ///刚好跳到b位置
    ll up =b-max((ll)0,x-sum[k]);///x-sum[k] 在b下面 --> 向上跳的步数并且最多走到0位置
    ll res=k+max((ll)0,up-stop); ///加入走了k步,再往上走,总共 k+up-stop 步
    ///up - stop ,往上走就不需要停顿了,up的步数比停顿的多 用up 顶替停顿,
    return min(step+res,dfs(x-sum[k-1],step+k,stop+1));///取现在向上反 和继续向下跑的最小的那个
}

int main()
{
    init();
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld%lld",&a,&b);
        if(a<=b)
        {
            printf("%lld\n",b-a);
            continue;
        }
        else
            printf("%lld\n",dfs(a,0,0));
    }
    return 0;
}
时间: 2024-12-28 02:30:39

2016暑假多校联合---Windows 10的相关文章

2016暑假多校联合---Substring(后缀数组)

2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a string, he has to calculate the total number of its distinct substrings. But ?? thinks that is too easy, he wants to make this problem more interesti

2016暑假多校联合---Rikka with Sequence (线段树)

2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Yuta has an array A with n numbers. Then he make

2016暑假多校联合---Another Meaning

2016暑假多校联合---Another Meaning Problem Description As is known to all, in many cases, a word has two meanings. Such as “hehe”, which not only means “hehe”, but also means “excuse me”. Today, ?? is chating with MeiZi online, MeiZi sends a sentence A to

2016暑假多校联合---Death Sequence(递推、前向星)

原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historian living in 1st century. He and his 40 comrade soldiers were trapped in a cave, the exit of which was blocked by Romans. They chose suicide over captu

2016暑假多校联合---Joint Stacks (STL)

HDU  5818 Problem Description A stack is a data structure in which all insertions and deletions of entries are made at one end, called the "top" of the stack. The last entry which is inserted is the first one that will be removed. In another wor

2016暑假多校联合---Counting Intersections

原题链接 Problem Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarantee that no two segments share the same endpoint, no covered segments, and no segments

2016暑假多校训练参赛感想

参赛感想 这是第一次参加暑假多校训练,应该也会是人生中最后一次,我真的很庆幸能参加这个训练,和全国几乎所有高校的ACMer一起在一个平台上做题!昨天为止多校已经完全结束,今天看到叉姐的训练感想(叉姐的感想链接),我觉得我也有必要写下自己的训练感想. 人的眼界总是狭窄的,当在自己的学校站在前几名的时候觉得自己还不错,应该会有不错的将来,但是当第一次参加国赛(2015 南阳站)的时候我便被别人实力所震撼,我突然觉得自己在别人的眼里简直就是小学生,菜到不行.别人在5个小时可以AK,而我连最水的题也要想

Hyper-V 2016 系列教程38 在 Windows 10 上安装 Hyper-V

启用 Hyper-V 以在 Windows 10 上创建虚拟机.可以通过多种方式启用 Hyper-V,包括使用 Windows 10 控制面板.PowerShell(我的最爱)或使用部署映像服务和管理工具 (DISM). 本文档将逐一介绍每个选项. 注意:Hyper-V 作为可选功能内置于 Windows -- 无 Hyper-V 下载或可安装的组件. 检查要求 Windows 10 企业版.专业版或教育版 具有二级地址转换 (SLAT) 的 64 位处理器. CPU 支持 VM 监视器模式扩展

Hyper-V 2016 系列教程39 在 Windows 10中使用 Hyper-V 和 Windows PowerShell

注:以下内容部分取自微软官网: 现在你已基本了解如何部署 Hyper-V.创建虚拟机和管理这些虚拟机,让我们研究一下如何使用 PowerShell 来自动执行其中大部分活动. 返回 Hyper-V 命令列表 单击 Windows"开始"按钮,键入"PowerShell". 运行以下命令以显示适用于 Hyper-V PowerShell 模块的 PowerShell 命令的可搜索列表. PowerShell Get-Command -Module hyper-v |