題目鏈接:
Help is needed for Dexter
題目解析:
這個題看起來蠻水的…不過想要快速想出正解還是有一定難度。
核心思想是每次操作後,使儘可能多的數字等價。
舉個栗子:1 2 3 4 5 6這六個數字,把4,5,6同時減去min(4,5,6)=4得0,1,2.等價於 1,2,3。換句話說,f(6)=f(3)+1.
這樣就得到了一個遞歸關係:f(n)=f(n/2)+1,f(1)=1.
總感覺有一道區域賽題跟這道題思路很相似然鵝我一時想不起來
AC代碼 :
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define ll long long
ll n,ans;
ll dfs(ll x)
{
if(x==1) return 1;
return dfs(x/2)+1;
}
int main()
{
while(scanf("%lld",&n)!=EOF)
printf("%lld\n",dfs(n));
}