hdu 5802 Windows 10 思维
来源:互联网 发布:智明创发软件待遇 编辑:程序博客网 时间:2024/06/05 18:52
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.
Next T line,each line contains two numbers
21 57 3
44
题意:有3种操作 1:向下 连续向下的话,这次向下是 上次的*2
2:休息,不动 下次向下从 1开始
3:往上走一步
贪心的想法是,走到离q最近的上(1<<k)-1 和 下(1<<(k+1))-1,我们贪心的觉得这样走到它下面不断往上走,和在上界休息+1然后再往下是最优的,最后往上走的时候减去休息的时间就是最小的时间了,因为休息和往上走一步的时间是一样的
#include <bits/stdc++.h>using namespace std;typedef long long ll;ll a,b;ll log(ll x,ll y){ll k=0;while((1ll<<k)-1ll<(x-y)) k++;return k;}ll dfs(ll x,ll y,ll step,int rest){if(x==y) return step;ll k=log(x,y);if(max(0ll,x-(1ll<<k)+1ll)==y) return step+k;ll up=y-max(0ll,x-(1ll<<k)+1ll);ll tmp=max(0ll,up-rest);return min(tmp+k+step,dfs(x-(1ll<<(k-1))+1ll,y,step+k,rest+1));}int main(){int t;scanf("%d",&t);while(t--){scanf("%lld%lld",&a,&b);if(a<=b) printf("%lld\n",b-a );else printf("%lld\n",dfs(a,b,0,0) );}}
阅读全文
0 0
- hdu 5802 Windows 10 思维
- hdu 5802 Windows 10 (贪心 + 思维)
- hdu 5802 Windows 10
- hdu 5802 Windows 10
- hdu 5802 windows 10
- HDU 5802 Windows 10
- hdu 5802 Windows 10 (贪心)
- HDU 5802 Windows 10(dfs)
- HDU 5802 Windows 10【贪心】
- HDU 5802 Windows 10 (贪心)
- hdu 5802 Windows 10 (贪心+dfs)
- HDU 5802 Windows 10(dfs)
- HDU-5802-Windows 10-贪心+dfs
- HDU 5802 Windows 10(贪心+DFS)
- hdu 5802——Windows 10
- HDU-5802-Windows 10(DFS+贪心)
- HDU 5802 Windows 10(贪心+dfs)
- HDU 5802 Windows 10 (贪心+DFS)
- 用JavaScript获取XML中的数据
- MyBatis sqlMapper.xml 传入String类型参数报错,invalid comparison: java.util.LinkedHashMap and java.lang.Strin
- Linux驱动并发处理---信号量
- GIT 使用
- 图的深度优先遍历
- hdu 5802 Windows 10 思维
- emacs 按键定制 (类似:vim leader)
- go语言中的import
- Linux驱动并发处理---互斥体(用处最多)
- 21天学通python——第三天
- javascript获取地址栏url方法(记录一下)
- NOIP2013普及组-车站分级
- 自定义消息作业类型该怎么用
- 字符串的最大递增子串