hdu 5802 Windows 10 (dfs)
Windows 10
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2191 Accepted Submission(s): 665
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.
Next T line,each line contains two numbers p and q (0≤p,q≤109)
1 5
7 3
4
题解:
先尽可能往下降然后升回来,或者尽可能往下降后停然后再往下降,于是就能将问题变成一个子问题,然后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)的更多相关文章
- hdu 5802 Windows 10 贪贪贪
传送门:hdu 5802 Windows 10 题意:把p变成q:升的时候每次只能升1,降的时候如果前一次是升或者停,那么下一次降从1开始,否则为前一次的两倍 官方题解: 您可能是正版Windows ...
- HDU 5802 Windows 10 (贪心+dfs)
Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...
- HDU 5802 Windows 10
传送门 Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 多校6 1010 HDU5802 Windows 10 dfs
// 多校6 1010 HDU5802 Windows 10 // 题意:从p到q有三种操作,要么往上升只能1步,要么往下降,如果连续往下降就是2^n, // 中途停顿或者向上,下次再降的时候从1开始 ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- hdu5802 Windows 10 贪心
Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- windows 10开启bash on windows,配置sshd,部署hadoop
1.安装Bash on Windows 这个参考官网步骤,很容易安装,https://msdn.microsoft.com/en-us/commandline/wsl/install_guide 安装 ...
- hdu-5802 Windows 10(贪心)
题目链接: Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 获取微软原版“Windows 10 推送器(GWX)” 卸载工具
背景: 随着Windows 10 免费更新的结束,针对之前提供推送通知的工具(以下简称GWX)来说使命已经结束,假设您还未将Windows 8.1 和Windows 7 更新到Windows 10 的 ...
随机推荐
- $ 一步一步学Matlab(3)——Matlab中的数据类型
小学时候我们就知道,数学中有自然数.整数.分数.小数等等很多种类型的数.到了中学,我们又发现了其实还有无理数.复数这些有些特殊的数.到了大学学了高等数学之后,我们又知道了其实还存在着无穷大.无穷小这样 ...
- 重定向符号和tee命令区别
来源:http://zyp88.blog.51cto.com/1481591/1604036 功能说明:读取标准输入的数据,并将其内容输出成文件. 语 法:tee [-ai][--help][-- ...
- Swap交换分区--continue
Linux内核为了提高读写效率与速度,会将文件在内存中进行缓存,这部分内存就是Cache Memory(缓存内存).即使你的程序运行结束后,Cache Memory也不会自动释放.这就会导致你在Lin ...
- FFmpeg 入门(4):线程分治
本文转自:FFmpeg 入门(4):线程分治 | www.samirchen.com 概览 上一节教程中,我们使用 SDL 的音频相关的函数来支持音频播放.SDL 起了一个线程来在需要音频数据的时候去 ...
- 20135302魏静静——linux课程第五周实验及总结
linux课程第五周实验及总结 一.学习总结 给MenuOS增加time和time-asm命令(四步操作命令) rm menu -rf 强制删除git clone http://github.com/ ...
- sublime text3 授权码
适用于 Sublime Text 3 Build3126 64位 官方版 -– BEGIN LICENSE -– Michael Barnes Single User License EA7E-821 ...
- ng2 quickstart-primeng
1.导入quickstart-angular项目 2.安装primeng npm install primeng 3.安装@angular/animations npm install @angula ...
- UVa 11396 爪分解(二分图判定)
https://vjudge.net/problem/UVA-11396 题意: 给出n个结点的简单无向图,每个点的度数均为3.你的任务是判断能否把它分解成若干爪.每条边必须属于一个爪,但同一个点可以 ...
- Eclipse解决乱码问题
使用Eclipse的时候发现有些格式的文件会乱码单个文件设置了没问题,但是在项目上设置却不起作用. 解决方法如下: Windows -> Preferences -> General -& ...
- cygwin 获取root高级权限
cygwin安装完成后没有passwd文件解决方法