Windows 10

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2191    Accepted Submission(s): 665

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

题解:

先尽可能往下降然后升回来,或者尽可能往下降后停然后再往下降,于是就能将问题变成一个子问题,然后dfs就好,需要注意的是由于升也可以打断连续降的功效,所以应该记录停顿了几次,以后上升的时候先用停顿补回来,不够再接着升,时间复杂度O(Tlogq)

#include <bits/stdc++.h>

using namespace std;
const int inf=0x7fffffff;
typedef long long ll;
ll res;
int T;
long long p,q;
long long sum[]; void dfs(ll x,ll y,ll ti,ll stop)
{
if (x==y) {res=min(res,ti); return;} int k=;
while(x-sum[k]>y) k++; if (x-sum[k]==y) { res=min(res,ti+k); return;}
ll up=q-max((ll),x-sum[k]);
res=min(res,ti+k+max((ll),up-stop)); //停顿可以替换向上按
dfs(x-sum[k-],y,ti+k,stop+); //停顿次数+1,向下减音量从1开始
return;
}
int main()
{ for(int i=;i<=;i++)
sum[i]=(<<i)-; scanf("%d",&T);
for(;T>;T--)
{
scanf("%lld%lld",&p,&q);
if (p<=q) printf("%lld\n",q-p);
else
{
res=inf;
dfs(p,q,,);
printf("%lld\n",res);
}
}
return ;
}

hdu 5802 Windows 10 (dfs)的更多相关文章

  1. hdu 5802 Windows 10 贪贪贪

    传送门:hdu 5802 Windows 10 题意:把p变成q:升的时候每次只能升1,降的时候如果前一次是升或者停,那么下一次降从1开始,否则为前一次的两倍 官方题解: 您可能是正版Windows ...

  2. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...

  3. HDU 5802 Windows 10

    传送门 Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  4. 多校6 1010 HDU5802 Windows 10 dfs

    // 多校6 1010 HDU5802 Windows 10 // 题意:从p到q有三种操作,要么往上升只能1步,要么往下降,如果连续往下降就是2^n, // 中途停顿或者向上,下次再降的时候从1开始 ...

  5. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

  6. hdu5802 Windows 10 贪心

    Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  7. windows 10开启bash on windows,配置sshd,部署hadoop

    1.安装Bash on Windows 这个参考官网步骤,很容易安装,https://msdn.microsoft.com/en-us/commandline/wsl/install_guide 安装 ...

  8. hdu-5802 Windows 10(贪心)

    题目链接: Windows 10 Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others ...

  9. 获取微软原版“Windows 10 推送器(GWX)” 卸载工具

    背景: 随着Windows 10 免费更新的结束,针对之前提供推送通知的工具(以下简称GWX)来说使命已经结束,假设您还未将Windows 8.1 和Windows 7 更新到Windows 10 的 ...

随机推荐

  1. android 如何获取当前的Activity类名

    比如友盟统计页面停留时间,咱们需要知道当前页面停留了多久. 一般我们都有一个父类Activity,用下面的方法可以获得完整的包名.类名结构 this.getLocalClassName() 输出如下: ...

  2. 20145316许心远《Java学习笔记》第三周总结

    20145316许心远<Java程序设计>第3周学习总结 教材学习内容总结 一.定义类: 类定义时使用class关键字 如果要将x绑定到新建的对象上,可以使用"="制定 ...

  3. 前端学习之JavaScript中的 NaN 与 isNaN

    NaN NaN 即 Not a Number ,不是一个数字. 在 JavaScript 中,整数和浮点数都统称为 Number 类型 .除此之外,Number 类型还有一个很特殊的值,即 NaN . ...

  4. CF1155D Beautiful Array(动态规划)

    做法 \(f_{i,0}\)表示以\(i\)结尾未操作时的最大值 \(f_{i,1}\)表示以\(i\)结尾正在操作时的最大值 \(f_{i,2}\)表示以\(i\)结尾已结束操作时的最大值 Code ...

  5. BeanFactory与ApplicationContext

    本文总结自:https://www.cnblogs.com/xiaoxi/p/5846416.html 我们常说的Spring容器(即Spring Ioc 容器),是如何创建bean的? BeanFa ...

  6. python3执行js之pyexecjs

    执行js的三种方法:1.阅读js代码,将之转成python2.找到js代码,用python第三方库执行相关代码 python2-pyv8 python3-pyexecjs3.用selenium驱动浏览 ...

  7. fatal: refusing to merge unrelated histories的解决方案

    最近更新了git版本,发现在github上建立了一个仓库,然后关联本地库的时候pull失败,错误为fatal: refusing to merge unrelated histories,查找后找到了 ...

  8. ASP.NET OAuth Authorization - Difference between using ClientId and Secret and Username and Password

      What I don't fully understand is the use of ClientId and Secret vs Username and Password. The code ...

  9. DataStage系列教程 by Bluebreeze

    突发奇想,用了这么久的DataStage,想要写点东西祭奠那逝去的岁月.希望可以坚持一直写完. DataStage系列教程 (Change Capture) DataStage系列教程 (Pivot_ ...

  10. POJ - 3169 差分约束

    题意:n头牛,按照编号从左到右排列,两头牛可能在一起,接着有一些关系表示第a头牛与第b头牛相隔最多与最少的距离,最后求出第一头牛与最后一头牛的最大距离是多少,如         果最大距离无限大则输出 ...