标签:== cout mask inpu int BMI else put mes
5 17
4
dfs,不过要注意0的时候
#pragma GCC optimize(2) #include<bits/stdc++.h> #include <math.h> using namespace std; typedef long long ll; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } const int maxn=1e5+100; int n,k; int dfs(int n,int k){ if(n>=k){ return n-k; } if(k%2==0){ return min(k-n,dfs(n,k/2)+1); } else{ return min(dfs(n,k+1),dfs(n,k-1))+1; } } void inint(){ cin>>n>>k; } int main(){ inint(); int ans; if(n==0){ n=1; ans=1; } else{ ans=0; } int p=ans+dfs(n,k); cout<<p; }
标签:== cout mask inpu int BMI else put mes
原文地址:https://www.cnblogs.com/lipu123/p/12752659.html