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 的 ...
随机推荐
- [转]Raanan Fattal - Image and Video Upscaling from Local Self-Examples 图像放大
转自:http://www.sigvc.org/bbs/thread-1032-1-1.html 论文链接:http://www.cs.huji.ac.il/~raananf/projects/lss ...
- cocos2d-x 2.x.x 新建工程 android下的 org文件夹丢失
cocos2d-x 2.x.x 新建工程之后... 打开android项目..会发现src下没有org文件... 解决方法一: cocos2d-x-2.2.0\cocos2dx\platform\an ...
- JSON 转 对象
Json对象与Json字符串的转化.JSON字符串与Java对象的转换 一.Json对象与Json字符串的转化 1.jQuery插件支持的转换方式: $.parseJSON( jsonstr ); ...
- Eclipse 导入Maven 项目报错
新建Maven项目时出错:org.apache.maven.archiver.MavenArchiver.getManifest 新建Maven项目时出错:org.apache.maven.arc ...
- IPMI的几个问题
IPMI针对大量监控.控制和自动回复服务器的作业,提供了智能型的管理方式.此标准适用于不同的服务器拓朴学,以及Windows.Linux. Solaris.Mac或是混合型的操作系统.此外,由于IPM ...
- oracle中add_months函数的用法
如果需要取上一个月的数据,并且每天都要进行此操作,每次都需要改时间,的确非常的麻烦,所以想到了oracle add_months函数这个函数 oracle add_months函数: oracle a ...
- Python笔记 #03# Help!
源:DataCamp datacamp 的 DAILY PRACTICE + 日常收集. Functions Built-in functions Help! Multiple arguments ...
- Python3.x:python: extend (扩展) 与 append (追加) 的区别
Python3.x:python: extend (扩展) 与 append (追加) 的区别 1,区别: append() 方法向列表的尾部添加一个新的元素.只接受一个参数: extend()方法只 ...
- webservice、WSDL简介
Webservice是跨平台.跨语言的远程调用技术 通信机制的本质是xml数据交换 采用soap协议进行通信 而WSDL 指网络服务描述语言 (Web Services Description Lan ...
- 20135320赵瀚青LINUX第二章读书笔记
第二章-从内核出发 获取内核代码 使用git 获取最新提交到版本树的一个副本 $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/tor ...