题意:每次从序列中选出几个数同时减去一个数,求最少的操作步骤,找规律:
f(n) = f(n/2) + 1; 我们保留1~n/2,把剩下的数同时减去n/2+1,得到序列1,2...,n/2,0,1...(n-1)/2,它等价于1,2...n/2,所以f(n) = f(n/2)+1;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int f(int n){
return n == 1 ? 1 : f(n/2) + 1;
}
int main(){
int n;
while (scanf("%d",&n) != EOF)
printf("%d\n",f(n));
return 0;
}