传送门

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. logstash搭建日志追踪系统

    前言 开始博客之前,首先说下10月份没写博客的原因 = =. 10月份赶上国庆,回了趟老家休息了下,回来后自己工作内容发生了点改变,开始搞一些小架构的东西以及研究一些新鲜东西,当时我听到这个消息真的是 ...

  2. Qt中forward declaration of struct Ui::xxx的解决

    每当你新键一个 QT设计界面, QT会自动生成yyy.ui文件,如 <?xml version="1.0" encoding="UTF-8"?> & ...

  3. flex弹性布局学习笔记

    前言 资料来源于网络,本人只是对此作了一下操作,记录于此以便以后查阅.目的在于梳理自己前端凌乱的知识点. 本文根据 Brian Franco 的一个flexbox.scss库来记录 入职新公司前对移动 ...

  4. HTTP请求头参数

      Accept-Language: zh-cn,zh;q=0.5 意思:浏览器支持的语言分别是中文和简体中文,优先支持简体中文. 详解: Accept-Language表示浏览器所支持的语言类型: ...

  5. [HDOJ5439]Aggregated Counting(乱搞)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5439 题意:按规则构造一个数列a a(1)=1 a(2)=2 a(2)=2 -------> 写两个 ...

  6. [BZOJ1299]巧克力棒(博弈论)

    题目:http://hzwer.com/1976.html 分析:先Orz hzwer 对于盒子外面的巧克力棒,就是Nim游戏. 所以就很容易想到先手第一步最好从盒子中取出m根巧克力棒,使得这些巧克力 ...

  7. javascript 函数声明与函数表达式的区别

    先看一段代码 var f = function g() { return 1; }; if (false) { f = function g(){ return 2; }; } alert(g()); ...

  8. 很简单的多线程访问python嘿嘿嘿

    import urllib import socket from threading import * url = "http://www.baidu.com/s?ie=UTF-8& ...

  9. c#模拟表单POST数据,并获取跳转之后的页面

    直接看代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...

  10. angularjs实现时钟效果

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...