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

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

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

    2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...

  2. 2016暑假多校联合---A Simple Chess

    2016暑假多校联合---A Simple Chess   Problem Description There is a n×m board, a chess want to go to the po ...

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

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  4. 2016暑假多校联合---To My Girlfriend

    2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...

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

    2016暑假多校联合---Another Meaning Problem Description As is known to all, in many cases, a word has two m ...

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

    原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...

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

    原题链接 Problem Description Given some segments which are paralleled to the coordinate axis. You need t ...

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

    HDU  5818 Problem Description A stack is a data structure in which all insertions and deletions of e ...

  9. 2016暑假多校联合---GCD

    Problem Description Give you a sequence of N(N≤100,000) integers : a1,...,an(0<ai≤1000,000,000). ...

随机推荐

  1. HTML5 的 localStorage(本地数据库) 的用法

    判断浏览器是否支持localStorage可以使用下面的代码:if(window.localStorage){     alert("支持localStorage") }else{ ...

  2. vue-cli创建项目

  3. How Google Tests Software - The Life of a TE

    By James WhittakerThe Test Engineer is a newerrole within Google than either SWEs or SETs. As such, ...

  4. easyuidatagrid中load,reload,loadData的区别。

    摘要:datagrid中有load,reload,loadData那三个方式,皆是加载数据的,但又有差别.下面让我们一起来看看: 首先,load方法,比如我已经定义一个datagrid的id为grid ...

  5. Zend Studio导入ThinkPHP工程

    1.一般来说,thinkPHP文件工程(简称php工程)要部署到www下面,那么可以先复制一份php工程到非www文件夹的地方(如桌面): 2.打开zend studio右键,File-New-Loc ...

  6. writing-mode改变文字书写方式

    古代书写方式都是垂直方向上的,如果要实现这种效果的话,还是挺麻烦的,不过现在CSS3有一个"writing-mode"属性,它可以改变文字的书写方式. writing-mode:h ...

  7. android studio 使用gradle 导出jar包,并打包assets目录

    警告:本文年久失修. 随着android studio的升级 ,gradle的升级,严格按照本文的代码去做可能不会成功,希望依然可以作为解决问题的思路. 最近项目在做一个sdk,供别的开发者使用,所以 ...

  8. try,catch,throw-----C++

    1.try,catch,throw: try包含你要防护的代码 ,称为防护块. 防护块如果出现异常,会自动生成异常对象并抛出. catch捕捉特定的异常,并在其中进行适当处理. throw可以直接抛出 ...

  9. Project简介

    Microsoft Project (Project)是一个国际上享有盛誉的通用的项目管理工具软件,凝集了许多成熟的项目管理现代理论和方法,可以帮助项目管理者实现时间.资源.成本的计划.控制,协助项目 ...

  10. 给 Web 前端开发人员推荐20款 CSS 编辑器

    CSS 和 HTML,JavaScript 是网页的基础,作为前端开发人员,对这三者都要很熟悉.特别是未来流行全栈开发的时代,每项技术都是你知识结构中必要的一个节点. 在开发中,选择好工具是非常重要的 ...