传送门

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. 文本比较算法Ⅱ——Needleman/Wunsch算法

    在"文本比较算法Ⅰ--LD算法"中介绍了基于编辑距离的文本比较算法--LD算法. 本文介绍基于最长公共子串的文本比较算法--Needleman/Wunsch算法. 还是以实例说明: ...

  2. 十分钟掌握Activity的生命周期与启动模式

    1. Activity的生命周期 正常情况下的Activity生命周期如下图所示(来自Android Developer): 当资源相关的系统配置变更时(比如设备屏幕方向改变,键盘可见性变化),会导致 ...

  3. 使用markdown编辑evernote(印象笔记)的常用方法汇总

    原文发表在我的博客主页,转载请注明出处 前言 正所谓工欲善其事,必先利其器,本文将要介绍的evernote和markdown都是程序员必备的工具 虽然国内现在有了很多evernote的替代品,做的比较 ...

  4. grootJsAPI文档

    groot.view(name,factory) 用于创建一个modelView对象与指令gt-view对应 参数 用途 name 创建的modelView的名称,用groot.vms[name]可以 ...

  5. HTML5+JS 《五子飞》游戏实现(二)路线分析和资源准备

    上一节 里沃特与我们分享了<五子飞>的下棋规则,可能有些伙伴看得不清楚,像我们码农还是看到代码比较靠谱.下面就把可以走棋的路线跟大家说一下. 假设从左上角开始,以0开始编号,往右数(没看第 ...

  6. OpenFlow

    What is OpenFlow? OpenFlow is an open standard that enables researchers to run experimental protocol ...

  7. 内网穿透神器ngrok——将本地项目驾到外网

    相信做Web开发的同学们,经常会遇到需要将本地部署的Web应用能够让公网环境直接访问到的情况,例如微信应用调试.支付宝接口调试等.这个时候,一个叫ngrok的神器可能会帮到你,它提供了一个能够在公网安 ...

  8. Android开发之Fragment

    一.Fragment生命周期: 二.动态添加Fragment的三步: 1.获得Fragment的管理者FragmentManager FragmentManager fragmentManager = ...

  9. 基本数据类型-列表_元组_字典_day4

    一.列表(list)书写格式:[] #通过list类创建的 li = [1, 12, 9, ", 10, ],"庞麦郎"], "ales", True ...

  10. OAuth in One Picture

    近年来,OAuth在各种开放平台的引领下变得非常流行,上图是OAuth协议认证的全过程,图本身已经比较详细,这里不再赘述. 从上图中可以看出,OAuth协议中有三个角色: User, Consumer ...