HDU 5802 Windows 10 (贪心+dfs)
Windows 10
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5802
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
Source
2016 Multi-University Training Contest 6
##题意:
要把音量从p调节到q. 每次调节需要1秒:
1. 按up会+1.
2. 按down:若上一秒是休息/up则-1;若上一秒下降x则-2*x.
##题解:
比赛的时候没有想清楚,看了题解后才知道贪心就可以了.
若pq , 贪心的想法是一直按down(中间可能停顿)直到p
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 150
#define mod 110119
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;
LL s, t;
LL dfs(LL cur, LL step, LL stop) {
if(cur == t) return step;
LL down = 0;
while(cur - (1<<down) + 1 > t) down++;
step += down;
if(cur - (1<<down) + 1 == t) return step;
LL up = t - max(0LL, cur - (1<<down) + 1);
return min(step+max(up-stop,0LL), dfs(cur-(1<<(down-1))+1, step, stop+1));
}
int main(int argc, char const *argv[])
{
//IN;
int T; cin >> T;
while(T--)
{
cin >> s >> t;
LL ans = 0;
if(s <= t) ans = t - s;
else ans = dfs(s, 0, 0);
printf("%lld\n", ans);
}
return 0;
}
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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 5802 Windows 10
传送门 Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- hdu5802 Windows 10 贪心
Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu-5802 Windows 10(贪心)
题目链接: Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 多校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 ...
- windows 10开启bash on windows,配置sshd,部署hadoop
1.安装Bash on Windows 这个参考官网步骤,很容易安装,https://msdn.microsoft.com/en-us/commandline/wsl/install_guide 安装 ...
- 【bzoj3252】攻略 贪心+DFS序+线段树
题目描述 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏. 今天他得到了一款新游戏<XX半岛>,这款游戏有n个场景(scene),某 ...
随机推荐
- launch genymotion simulator from command line
Command to launch genymotion headless - player --vm-name Nexus_4 if player is not already added to p ...
- 简单实现WPF界面控件换肤效果
效果如下如图:选择皮肤颜色 1.首先新建一个如图界面: 选择匹夫下拉框Xaml代码如下:三种颜色选项,并触发SelectionChanged事件 <ComboBox Height="2 ...
- jquery dialog-优雅的弹出框
前面一章已经对datepicker的使用,做了简单的说明.这一章主要对dialog如何使用做个说明. jquery ui-dialog在web开发中运用还是比较多的.最常见的例子就是登 ...
- VS2010解决方案不显示无法添加项目问题
问题:在VS2010中不显示解决方案,导致不能添加项目. 方法:工具-选项-项目和解决方案-选中“总是显示解决方案”,ok
- web交互方式
轮询:客户端定时向服务器发送Ajax请求,服务器接到请求后马上返回响应信息并关闭连接. 优点:后端程序编写比较容易. 缺点:请求中有大半是无用,浪费带宽和服务器资源. 实例:适于小型应用. 长轮询:客 ...
- 自己遇到的Android虚拟机出现的错误及解决方法【不断更新】
2012.11.9 第一个: [2012-11-09 13:15:14 - Tesa] Android Launch! [2012-11-09 13:15:14 - Tesa] The connect ...
- [转帖]Asp.NET 弹出页面
原文链接:http://www.cnblogs.com/adi-liu/archive/2008/07/18/1246091.html ASP.NET 弹出对话框和页面之间传递值的经验总结 今天碰到一 ...
- 【C#学习笔记】读access2007
using System; using System.Data.OleDb; namespace ConsoleApplication { class Program { static void Ma ...
- poj 3181 Dollar Dayz
题意:给定一个数p,要求用K种币值分别为1,2,3...K的硬币组成p,问方案数,1,2,2和2,2,1算一种方案即与顺序无关,n <= 1000,k <= 100// 用完全背包做了 这 ...
- 一天一个Java基础——序列化
1.概念 Java的“对象序列化”能将一个实现了Serializable接口的对象转换成一组byte,这样日后要用这个对象的时候,能把这些byte数据恢复出来,并据此重新构建那个对象. 对象序列化能实 ...