hdu 5802——Windows 10
生活随笔
收集整理的這篇文章主要介紹了
hdu 5802——Windows 10
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:給定兩個音量,需要從l調到r,每次只能向上一下或者向下(1,2,4,2^n)下(連續向下的情況下),每次可以停歇或向上來打斷向下的連續性,最少需要多少步?
思路:當l小于r時顯然答案是r-l,當l>r時那么不停地下降到r附近,此時只需要在r的上方和下方挑選最少的步數即可。注意向上也可以打斷向下的連續性。
code:
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <sstream> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <map> #include <set> #include <bitset>using namespace std;typedef long long ll; typedef unsigned long long ull; typedef long double ld;const int INF=0x3fffffff; const int inf=-INF; const int N=105; const int M=2005; const int mod=1000000007; const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x)) #define cpy(x,a) memcpy(x,a,sizeof(a)) #define ft(i,s,n) for (int i=s;i<=n;i++) #define frt(i,s,n) for (int i=s;i>=n;i--) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lrt rt<<1 #define rrt rt<<1|1 #define middle int m=(r+l)>>1 #define lowbit(x) (x&-x) #define pii pair<int,int> #define mk make_pair #define IN freopen("in.txt","r",stdin) #define OUT freopen("out.txt","w",stdout)int read() {char ch;while (ch = getchar(), !isdigit(ch));int res = ch - '0';while (ch = getchar(), isdigit(ch))res = res * 10 + ch - '0';return res; } ll powm(ll a,ll n){ll ans=1;while (n){if (n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans%mod; } //++++++++++++密++++++++++++++封++++++++++++++++++++線ll n,m; ll sol(ll n,ll stp){if (n<=m) return max(0LL,m-n-stp);ll nn=n,p=1,sp=0;while (n-m>0){n-=p;p<<=1;sp++;if (n==m) return sp;}sp+=min(sol(n+p/2,++stp),sol(max(0LL,n),stp));return sp; } int main() {int T=read();ft(ca,1,T){scanf("%lld%lld",&n,&m);cout<<sol(n,0)<<endl;} }總結
以上是生活随笔為你收集整理的hdu 5802——Windows 10的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu5446——Unknown Tre
- 下一篇: 新闻类app,每次上拉和下拉刷新都有数据