HDU5802-Windows 10
来源:互联网 发布:asp会员管理系统源码 编辑:程序博客网 时间:2024/06/05 19:48
Windows 10
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2305 Accepted Submission(s): 694
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
Recommend
wange2014
题意:调节音量p到q,上升音量每秒只能上升1,下降音量每秒为2*x,x为上一次下降的音量,如果下降时休息或者上升音量则x置为1,音量最低为0,问最少需要调节几次
解题思路:贪心的去选,每次下降到终点上的最近一点,或者终点下的一点,取一个最小值
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <cmath>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;LL sum[50], p, q;void init(){LL k = 1;sum[1] = 1;for (int i = 2; i <= 32; i++){k = k * 2;sum[i] = sum[i - 1] + k;}}LL dfs(LL x, int step, int stop){int k = 1;while (x - sum[k] > q) k++;if (x - sum[k] == q)return step + k;LL up = q - max((LL)0, x - sum[k]);LL tmp = k + max((LL)0, up - stop);return min(step + tmp, dfs(x - sum[k - 1], step + k, stop + 1));}int main(){int t;scanf("%d", &t);init();while (t--){scanf("%lld%lld", &p, &q);if (q >= p) { printf("%lld\n", q - p); continue; }printf("%lld\n", dfs(p, 0, 0));}return 0;}
阅读全文
0 0
- hdu5802 Windows 10
- hdu5802 Windows 10(贪心)
- HDU5802-Windows 10
- HDU5802 Windows 10[贪心+DFS]
- hdu5802 Windows 10(贪心搜索)
- 【HDU5802】Windows 10 (贪心 + dfs)
- 2016多校训练Contest6: 1010 Windows 10 hdu5802
- hdu5802
- 2016多校第6场1010 --hdu5802 搜索-剪枝+贪心
- windows 10
- Windows 10
- Windows 10
- Upgrade from Windows 8 to Windows 10
- [Windows 10] 体验windows10
- Windows 10 初步体验
- Windows 10 安装
- Windows 10快捷键一览
- windows 10偿鲜
- Hibernate框架简介基础
- 计算机视觉杂记(1)
- 第五次模拟(偶串)
- VMware 虚拟化编程(2) — 虚拟磁盘文件类型详解
- MySQL Community Server 5.7.19环境部署
- HDU5802-Windows 10
- pat乙级1004
- easyui Combotree默认选中某一项
- Nginx基础配置详解
- Dlib配置---Win7 与 Linux
- CF432 D
- Feel Good UVA
- 算法导论之哈希算法
- vim命令使用大全