当前位置:首页 > CN2资讯 > 正文内容

hdu-5802 Windows 10(贪心)

2天前CN2资讯

题目链接:

Windows 10

Time Limit: 2000/1000 MS (Java/Others)  

  Memory Limit: 65536/65536 K (Java/Others)


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 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   题意: 问从p到q的最短时间是多少?   思路:   看的别人的才知道怎么做,每次连续下降x次,一共下降2x-1的音量;每次下降到比q大或者比q小最接近q的数,为什么这样呢? 假设有两次的都连续下降x次.那么可以连成一个x+1的的下降,所以前边连续下降的次数比后边大;   AC代码:   /************************************************ ┆ ┏┓   ┏┓ ┆ ┆┏┛┻━━━┛┻┓ ┆ ┆┃       ┃ ┆ ┆┃   ━   ┃ ┆ ┆┃ ┳┛ ┗┳ ┃ ┆ ┆┃       ┃ ┆ ┆┃   ┻   ┃ ┆ ┆┗━┓   ┏━┛ ┆ ┆  ┃   ┃  ┆       ┆  ┃   ┗━━━┓ ┆ ┆  ┃  AC代马   ┣┓┆ ┆  ┃    ┏┛┆ ┆  ┗┓┓┏━┳┓┏┛ ┆ ┆   ┃┫┫ ┃┫┫ ┆ ┆   ┗┻┛ ┗┻┛ ┆ ************************************************ */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> //#include <bits/stdc++.h> #include <stack> #include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++) #define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) { char CH; bool F=false; for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar()); for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + '0'); putchar('\n'); } const LL mod=1e9+7; const double PI=acos(-1.0); const LL inf=1e18; const int N=2e5+10; const int maxn=2e3+14; const double eps=1e-12; LL ans,f[40]; void dfs(LL p,LL q,LL time,int num) { if(max(p,0LL)==q) { ans=min(ans,time); return ; } else if(max(p,0LL)<q) { LL temp=q-max(0LL,p); ans=min(ans,time+max(temp-num,0LL)); return ; } int l=1; while(p-(f[l]-1)>q)l++; dfs(p-(f[l]-1),q,time+l,num); if(l>1)dfs(p-(f[l-1]-1),q,time+l,num+1); } inline void solve(LL p,LL q) { ans=inf; dfs(p,q,0,0); printf("%lld\n",ans); } inline void Init() { f[0]=1; For(i,1,35)f[i]=f[i-1]*2; } int main() { int t; LL p,q; read(t); Init(); while(t--) { read(p);read(q); solve(p,q); } return 0; }

  

    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/27156.html

    分享给朋友:

    “hdu-5802 Windows 10(贪心)” 的相关文章

    探索美国冷门VPS:高性价比与个性化服务的优选

    在谈论VPS(虚拟专用服务器)时,人们往往会联想到那些知名的品牌和服务,而美国冷门VPS市场却是一个值得关注的领域。这些冷门VPS提供商虽然在整体市场中的知名度较低,但却为特定的用户群体和需求提供了颇具价值的服务。我在研究这个市场时,发现不少提供商在某些方面有着相当的优势,让我对这个冷门领域充满了好...

    OneTechCloud:高性价比VPS与独立服务器的最佳选择

    在了解OneTechCloud之前,我们先来探讨一下它的成立背景和发展历程。OneTechCloud,或称易科云,是一家自2019年就开始运营的国内小型主机商。虽然成立时间不久,但它迅速在市场上获得了一定的知名度。作为由中国团队经营的公司,OneTechCloud专注于提供海外VPS和独立服务器服务...

    如何解决甲骨文IP被墙的问题及有效方法

    谈到甲骨文,大家可能会联想到古老的文字和悠久的历史,然而随着信息技术的飞速发展,甲骨文的应用已经不仅仅局限于文化研究。在数据存储、信息管理等领域,甲骨文的IP(互联网协议)在全球范围内发挥着重要的作用。不幸的是,现如今许多用户却发现自己无法正常访问这些IP。这就是我们所说的“甲骨文IP被墙”的现象。...

    VPS去程测试:提升网络性能的关键策略与工具

    在当今数字化时代,VPS(虚拟专用服务器)为各类用户提供了极大的灵活性和控制力。为了确保这种服务能够表现出色,VPS去程测试成为了一个重要的话题。简单来说,去程测试是指从我本地设备到VPS服务器的数据传输路径的检查。这种测试能够帮助我了解数据包在传输过程中的表现,包括延迟和可能的瓶颈。 去程测试的重...

    ColoCrossing:优质VPS与安全托管服务提供商解析

    在美国,ColoCrossing作为一家老牌且独立的服务器和托管服务提供商,一直以来以其优质的IT解决方案著称。这家成立多年的公司,致力于满足不同类型客户的需求,无论是面向亚太地区还是欧美市场,它都有相应的数据中心来支持各种使用场景。我个人觉得他们的服务理念是非常值得推崇的,特别是在稳定性和可靠性方...

    WordPress reCAPTCHA插件:提升网站安全与用户体验的最佳解决方案

    reCAPTCHA插件概述 在今天的网络环境中,安全性愈发重要,尤其是对于使用WordPress的网站。WordPress reCAPTCHA插件成为了一种流行的解决方案,它借助Google强大的reCAPTCHA服务,帮助我们有效地区分真实用户和可能扰乱网站的机器程序。在我接触这个插件之后,发现它...