传送门

Windows 10

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 694    Accepted Submission(s): 200

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 $2x$ 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\le T\le 300000)$,cases number.
Next $T$ line,each line contains two numbers $p$ and $q (0\le p,q\le 10^9)$.

 

 

Output
The minimal seconds he should take
 

 

Sample Input
2

1 5
7 3
 

 

Sample Output
4
4
 
Author
UESTC
 
Source

 Solution:
首先明确题意:
the voice of his computer can larger than any dB but can't be less than $0$ dB.
这句话的意思是: 如果当前按一次down会导致音量减到负值, 那么按下down后, 音量就会变成0, 不能理解成: 当前不能按down.
$p\le q$的情况是trivial的, 下面考虑 $p>q$.
初步分析可以看出:
1. 一连串的down可以看成一个down, 下文中的的down指的都是一连串的down.
2. rest连接两个down, 然而这并没有什么用.
3. up是为了更好地down, 这个结论比较有用:
我们可以把up操作都放在最后进行. 之前的操作模式就是
down rest down rest ... down 一直down到q或q以下, 再up到q, 注意最后的up可以用之前的rest操作代替一部分或全部.

但是分析到这里暴力的复杂度仍然是不能承受的.
我们可以注意到一个贪心策略:
每次都尝试down到小于等于q然后再up回来, 或者down到大于q的最小值, rest一步继续down.
这个策略的正确性我还不会证.

Implementation
#include <bits/stdc++.h>
using namespace std; int res, p, q, s[], T; void dfs(int x, int p, int sub){
if(p+sub>=res) return;
int i=lower_bound(s, s+, x)-s, r=s[i]-x;
res=min(res, p+sub+i+max(, min(q, r-p)));
if(r) dfs(x-s[i-], p+, sub+i-);
} int main(){
for(int i=; i<; i++)
s[i]=(1LL<<i)-; for(cin>>T; T--; ){
scanf("%d%d", &p, &q);
if(p<=q) res=q-p;
else res=INT_MAX, dfs(p-q, , );
printf("%d\n", res);
}
}
 

HDU 5802 Windows 10的更多相关文章

  1. hdu 5802 Windows 10 贪贪贪

    传送门:hdu 5802 Windows 10 题意:把p变成q:升的时候每次只能升1,降的时候如果前一次是升或者停,那么下一次降从1开始,否则为前一次的两倍 官方题解: 您可能是正版Windows ...

  2. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...

  3. hdu 5802 Windows 10 (dfs)

    Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  4. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

  5. hdu5802 Windows 10 贪心

    Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  6. 获取微软原版“Windows 10 推送器(GWX)” 卸载工具

    背景: 随着Windows 10 免费更新的结束,针对之前提供推送通知的工具(以下简称GWX)来说使命已经结束,假设您还未将Windows 8.1 和Windows 7 更新到Windows 10 的 ...

  7. Windows 10 部署Enterprise Solution 5.5

    Windows 10正式版发布以后,新操作系统带来了许多的变化.现在新购买的电脑安装的系统应该是Windows 10.与当初用户不习惯Windows 7,购买新电脑后第一个想做的事情就是重装成XP,估 ...

  8. 如何通过官方渠道为Windows 10 添加具有中国特色的字体

    Windows 10的变化细节上个人认为要比Windows 8多很多,而且很多功能找到之后还是小惊喜,就是挺多好用的地方居然都不正经宣传一下,微软真是搞得悄悄地干活? 今天为大家介绍一下通过官方途径添 ...

  9. 如何修复Windows 10 Enterprise 在9月更新后图片全部由绘图板打开的情况

    在进行了本月更新日的洗礼之后,企业版的Windows 10 突然发现无法好好的进行图片查看. 因为更新之前,各种图片都是使用“照片程序”打开的(这个是photos app),然后更新之后,这个app就 ...

随机推荐

  1. 做中学之Vim实践教程

    做中学之Vim实践教程 Vim VIM是一个非常好的文本编辑器,很多专业程序员使用VIM编辑代码,即使以后你不编写程序,只要跟文本打交道,都应该学学VIM,可以浏览参考一下普通人的编辑利器--Vim这 ...

  2. spring boot/cloud 应用监控

    应用的监控功能,对于分布式系统非常重要.如果把分布式系统比作整个社会系统.那么各个服务对应社会中具体服务机构,比如银行.学校.超市等,那么监控就类似于警察局和医院,所以其重要性显而易见.这里说的,监控 ...

  3. css+div 浮动分块

    前段时间学过几天html,只是怀着了解的态度,能够读懂别人的页面,能够扒现成就行,一直没有自己动手去实践过,其实也不是没有实践过,前段时间扒了一个网页,想按照自己的要求来改,可后果是越改越乱.今天心血 ...

  4. 天龙客户端的ResourceManager

    今天培训的时候,Leader针对项目结构讲了很多分层架构的思想,思路,对我而言有很大的助益,学会了将需求分层,或者说先设计出各个层次,然后有需求后落实到对应的层次上,尤其对于刚开始的架构设计阶段,能把 ...

  5. JavaScript的理解记录(4)

    客户端JavaScript:客户端就是Web浏览器; 一. 前奏: Web文档(document):一些呈现静态信息的页面,虽然有的页面是会动的,但信息本身还是静态! Web应用:可以动态载入信息,相 ...

  6. 在Word2013中多次应用格式刷

    顾名思义,格式刷是为了方便需要跨区域操作时候,能快速的应用格式到相应文本.那么怎么使用word进行格式刷的多次使用呢.我们先来看单次的,这个比较容易,只要在先需要的格式单击一次格式刷,再到需要的文本执 ...

  7. 开发错误记录10: Butterknife8.1.0 提示NullPointerException空指针

    Butterknife 8.0以后的版本在引入到项目中有变动,按之前的引入方式之后, 会报 空指针! 正确的引入方法是:(在官方的文件上有说明的,记录是为了方便下次引入,直接复制到项目) 在项目的.g ...

  8. javascript获得客户端IP的又一方法

    <script language="JavaScript">VIH_BackColor = "palegreen";VIH_ForeColor = ...

  9. Hessian Matrix

    函数\(f\)的Hessian矩阵由是由它的二阶偏导数组成的方阵 \[ H = \begin{bmatrix} \dfrac{\partial^2 f}{\partial x_1^2} & \ ...

  10. Oracle数据库下sde用户系统表开放权限sql语句

    --sde用户登陆执行以下语句 grant insert, update, delete on sde.table_registry to PUBLIC; grant insert, update, ...