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. Node.js入门:包结构

        JavaScript缺少包结构.CommonJS致力于改变这种现状,于是定义了包的结构规范(http://wiki.commonjs.org/wiki/Packages/1.0 ).而NPM的 ...

  2. 记一次裸迁 MySQL 经历

    记一次裸迁MySQL经历 前言:博主企业有一台企业阿里云机器,因为安装了云锁,造成服务器动不动就给我所死服务器.(就是那种 chattr +i /bin/bash ,分分钟日死狗 )趁着周末,Boos ...

  3. Visual C++ 6.0使用教程

    Visual C++它大概可以分成三个主要的部分: 3. Platform SDK.这才是Visual C++和整个Visual Studio的精华和灵魂,虽然我们很少能直接接触到它.大致说来,Pla ...

  4. Unity3D 开发之shader教程(浅谈光照之漫反射diffuse)

    在游戏开发过程中,光照应该是必不可少部分,当然,这是指大多数的稍微大型一些的3D游戏会需要,给模型或者山山水水加上光照,会看上去更加的真实,获得更好的体验.一个本身不发光物体显示什么颜色,在于本身反射 ...

  5. 使用 jQuery & CSS3 实现翻转的作品集滑块

    作为 Web 开发人员,我想你一定见过各种各样的图片滑块效果.展示产品或者个人作品的方法有很多,其中之一是使用网格样式的滑块效果.在本教程中,我将分享如何使用 jQuery 和 CSS3 变换实现翻转 ...

  6. Foundation 5 发布!最先进的响应式前端框架

    数以百万计的设计师和工程师采用 Foundation 作为他们的产品和网站设计的前端框架.Foundation 是第一个响应式.语义化和移动优先的开源框架.最新发布的 Foundation 5 是最先 ...

  7. java类的初始化和对象的创建顺序

    学习java编程思想--类的初始化p146 类的加载顺序* 1加载器启动找到 xxx.class文件,通过extends关键字寻找基类,先加载基类* 2类初始化先初始化static成员变量和stati ...

  8. list的一些使用

    list无数据判断 在一次判断中,我这样: if(list!=null){ ... } 结果发现list为空数据的时候不管用,后来发现,list只要创建实例就不会是null,但可以为empty,因此 ...

  9. ASP.NET 文件下载

    using System; using System.Web; using System.IO; public partial class _Default : System.Web.UI.Page ...

  10. 阅读《LEARNING HARD C#学习笔记》知识点总结与摘要四

    又是一个周末,刚好有时间,又继续复习与总结了,希望能让大家受益,不足之处欢迎指正,谢谢! 十八. Lambda 1.Lambda表达式:匿名方法的另一种表现形式,它可以包含表达式和语句,且用于创建委托 ...