建设网站需要哪些认证,如何做市场推广,网站建设方案报价单,企业网站开发需要多钱题意#xff1a;给定两个音量#xff0c;需要从l调到r#xff0c;每次只能向上一下或者向下#xff08;1#xff0c;2#xff0c;4#xff0c;2^n#xff09;下#xff08;连续向下的情况下#xff09;#xff0c;每次可以停歇或向上来打断向下的连续性#xff0c;…题意给定两个音量需要从l调到r每次只能向上一下或者向下1242^n下连续向下的情况下每次可以停歇或向上来打断向下的连续性最少需要多少步
思路当l小于r时显然答案是r-l当lr时那么不停地下降到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 bitsetusing namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;const int INF0x3fffffff;
const int inf-INF;
const int N105;
const int M2005;
const int mod1000000007;
const double piacos(-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 is;in;i)
#define frt(i,s,n) for (int is;in;i--)
#define lson l,m,rt1
#define rson m1,r,rt1|1
#define lrt rt1
#define rrt rt1|1
#define middle int m(rl)1
#define lowbit(x) (x-x)
#define pii pairint,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 ans1;while (n){if (n1) ansans*a%mod;aa*a%mod;n1;}return ans%mod;
}
//密封线ll n,m;
ll sol(ll n,ll stp){if (nm) return max(0LL,m-n-stp);ll nnn,p1,sp0;while (n-m0){n-p;p1;sp;if (nm) return sp;}spmin(sol(np/2,stp),sol(max(0LL,n),stp));return sp;
}
int main()
{int Tread();ft(ca,1,T){scanf(%lld%lld,n,m);coutsol(n,0)endl;}
}