hdu5802 Windows 10(贪心搜索)
来源:互联网 发布:企业数据备份软件 编辑:程序博客网 时间:2024/05/17 03:14
思路:30w个样例1s...完全没有往搜索那个方面去想,一直想找一下规律...智障啊...
题解:
_您可能是正版Windows 10的受害者_ 直接贪心就好
比较直观的看法是使劲往下降,然后升回来
或者使劲往下降然后停顿然后再使劲往下降。。。
于是就能将问题变成一个子问题,然后dfs就好
需要注意的是由于按up键也可以打断连续向下的功效
所以应该记录停顿了几次,以后向上的时候用停顿补回来
#include<bits/stdc++.h>using namespace std;#define LL long longLL p,q;LL dfs(LL pp,LL qq,LL step,LL stop){ if(qq==pp)return step;LL move = 0;while(pp-(1<<move)+1 > qq)move++;if(pp-(1<<move)+1==qq)return step+move;LL up = qq-max((LL)0,pp-(1<<move)+1);LL res = move+max((LL)0,up-stop); return min(step+res,dfs(pp-(1<<(move-1))+1,qq,step+move,stop+1));}int main(){ int T;scanf("%d",&T);while(T--){scanf("%lld%lld",&p,&q);if(q>=p){printf("%lld\n",q-p);continue;}printf("%lld\n",dfs(p,q,0,0));}}
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.
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 numbersp and q (0≤p,q≤109)
Next T line,each line contains two numbers
Output
The minimal seconds he should take
Sample Input
21 57 3
Sample Output
44
Author
UESTC
Source
2016 Multi-University Training Contest 6
0 0
- hdu5802 Windows 10(贪心搜索)
- hdu5802 Windows 10(贪心)
- 【HDU5802】Windows 10 (贪心 + dfs)
- HDU5802 Windows 10[贪心+DFS]
- hdu5802 Windows 10
- HDU5802-Windows 10
- 2016多校第6场1010 --hdu5802 搜索-剪枝+贪心
- 2016多校训练Contest6: 1010 Windows 10 hdu5802
- hdu5802
- HDU 5802 Windows 10 (贪心)
- hdu 5802 Windows 10 (贪心 + 思维)
- HDU 5802 Windows 10(贪心+DFS)
- 【HDOJ5802】Windows 10 (贪心 + dfs)
- HDU-5802-Windows 10(DFS+贪心)
- HDU 5802 Windows 10(贪心+dfs)
- uvalive 3971 - Assemble(二分搜索 + 贪心)
- nyoj 疯牛(二分搜索+贪心)
- uvalive 3971 - Assemble(二分搜索 + 贪心)
- CharSequence与String的区别
- Kendo UI开发教程(15): Kendo MVVM 数据绑定(四) Disabled/Enabled
- 快速排序及优化
- 《UNIX环境高级编程》三文件I/O读书笔记
- 使用Markdown编辑器写博客
- hdu5802 Windows 10(贪心搜索)
- POJ 1917 字符串替换
- 适配器和映射器
- Oracle(入门二)
- [Python]--What are the differences between numpy arrays and matrices?
- Linux 使用ntfs-3g挂载NTFS最佳实践
- codeigniter的session(1)
- Qt预览图片(同一目录下),点击后单张显示
- 你必须知道的25道JavaScript核心面试题