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. 爱上MVC~为非法进行Action的用户提供HttpStatusCodeResult

    回到目录 对一MVC来说,它有Controller和Action,其中Action用来为页面提供数据和相关逻辑,并最后将页面渲染出来,而有些action是需要一些参数的,如文章的最终页,可能需要一个I ...

  2. 锋利的JQuery —— 选择器

    图片猛戳链接

  3. sql分组(orderBy、GroupBy)获取每组前一(几)条数据

    sql数据库实现分组并取每组的前1(几)条数据 测试数据准备工作: 根据某一个字段分组取最大(小)值所在行的数据: 创建表并且插入数据 ),Val )) , 'a1--a的第一个值') , 'b2b2 ...

  4. KnockoutJS 3.X API 第四章 数据绑定(5) 控制流component绑定

    本节目录: 一个例子 API 备注1:仅模板式的component 备注2:component虚拟绑定 备注3:传递标记到component绑定 内存管理 一个例子 First instance, w ...

  5. KnockoutJS 3.X API 第五章 高级应用(1) 创建自定义绑定

    您不仅限于使用内置的绑定,如click,value绑定等,您可以创建自己的绑定. 这是如何控制视图模型如何与DOM元素进行交互,并且为您提供了大量的灵活性,以便于以复用的方式封装复杂的行为. 注册绑定 ...

  6. 趣谈、浅析CRLF和LF

    作为程序员,在处理文件和输入输出的时候经常要跟CRLF和LF打交道.可能大家多少知道一些,但总是记不清楚,我也是这样的,因此写下这篇博文,作为记录. 首先,明确他们的意思:CR(回车),LF(换行). ...

  7. 浅谈attr()和prop()

    刚开始学JQ的时候 ,看到attr()和prop()这两个属性的时候感觉很迷茫,而且配合官方给出的推荐使用图: prop()可以做到的attr()完全都可以,而且做不到的attr()也可以做到.何用? ...

  8. 使用AssetsLibrary.Framework创建多图片选择控制器(翻译)

    系统的UIImagePickerController只能让用户选择单图片,而一般情况下,我们需要上传多张图片,这时应该可以同时选择多张图片,否则用户体验会很差.因此多图片选择器就诞生了. 在类库中,苹 ...

  9. OpenCASCADE Application Framework Data Framework Services

    OpenCASCADE Application Framework Data Framework Services eryar@163.com 一.概述Overview OpenCASCADE的数据框 ...

  10. android rectF

    new Rect(left , top, right , bottom) 这个构造方法需要四个参数这四个参数 指明了什么位置 ?我们就来解释怎么画 这个 矩形 这四个 参数 分别代表的意思是:left ...