hdu-5802 Windows 10(贪心)
题目链接:
Windows 10Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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; }
hdu5802 Windows 10(贪心搜索)搜索贪婪整合包
windows 7/windows10系统下自动挂载VHD文件windows10 系统
将Windows8或WindowsServer2012装在VHD上windows server 2012
解决ModuleNotFoundError: No module named 'psycopg2'的安装报错方法
解决ModuleNotFoundError: No module named 'ipython'错误的方法
解决modulenotfounderror: no module named _bz2的最佳方法
解决 modulenotfounderror: no module named 'urllib2' 错误的终极指南
Windows Server 2012 R2 Shutting down service:Windows Modules Installer 卡住windows server 2012 r2系统