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. getattribute()与getparameter()的区别

    1.它们取到的值不同.getAttribute取到的是对象(object),而getParameter取到的是String. 2.数据传递路劲不同.request.getParameter方法传递的数 ...

  2. Atitit 跨平台异常处理(2)--------异常转换 -----java c# js异常对象结构比较and转换

    Atitit 跨平台异常处理(2)--------异常转换 -----java c# js异常对象结构比较and转换 { "@type":"java.lang.Runti ...

  3. 更新日志 - fir.im Jenkins & Gradle 插件上线

    最近 fir.im 工程师们效率爆表,fir.im 实用工具集合又添加了新的成员-- Jenkins & Gradle 插件,让 App 打包上传更加简单快速. fir.im Jenkins ...

  4. C#获取文本文件的编码,自动区分GB2312和UTF8

    C# 获取文本文件的编码,自动区分GB2312和UTF8 以下是获取文件编码的一个类 using System; using System.IO; using System.Text; /// < ...

  5. IIS集成模式下,URL重写后获取不到Session值

    近期给公司网站添加了伪静态功能,但是今天发现了在伪静态的页面中,Session值是获取不到的. 原因是在伪静态请求的时候,Session请求被“过滤”掉了. 开始是把web.config文件中的mod ...

  6. C#委托(delegate)

    C#中委托(delegate)是一种安全地封装方法的类型,委托是面向对象的.类型安全的. 使用委托的步骤: 1.声明委托 public delegate void DelegateHandler(st ...

  7. JAVA EE Hibernate基础一之环境配置

    对于JAVA开发高级,hibernate是java三大框架之一,足以见得它的重要性,那么对于hibernate的使用大家有了解多少呢?从今天开始我将带领大家一道共同探讨一下hibernate的知识,h ...

  8. ISTool5.3.1汉化版使用教程

    ISTool是帮助你创建由Jordan Russell制作的Inno Setup编译器脚本的工具.Inno是一个出色的编译器,即使对于某些专业的安装制作程序,它唯一的缺点就是它的脚本必须手动编写. 这 ...

  9. Unity3D Player角色移动控制脚本

    1. 简介 在Unity3D中,有多种方式可以改变物体的坐标,实现移动的目的,其本质是每帧修改物体的position.之前写过类似的文章,这次增加了平时常用API的脚本,每个脚本均手打测试可用. 2. ...

  10. Elasticsearch——集群相关的配置

    cluster模块主要用于控制分片在节点上如何进行分配,以及何时进行重新分配 概览 下面的一些资料可以进行相关的配置: Cluster Level Shard Allocation用于配置集群中节点如 ...