UVa 11384 Help is needed for Dexter

题意:给定n,用最少的操作数把序列1到n中的所有数都变成0,每次可以选择一个或者多个数,同时减去一个相同的正整数

发现多画几次,f(n) = f(n/2) + 1,大概就是想要每次变化之后两端都尽可能对称的感觉

 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath> 
 5 #include<stack>
 6 #include<vector>
 7 #include<map> 
 8 #include<set>
 9 #include<queue> 
10 #include<algorithm>  
11 using namespace std;
12 
13 typedef long long LL;
14 const int INF = (1<<30)-1;
15 const int mod=1000000007;
16 const int maxn=1000005;
17 
18 int f(int n){
19     if(n == 1) return 1;
20     return f(n/2) + 1;
21 }
22 
23 int main(){
24     int n;
25     while(scanf("%d",&n) != EOF){
26         printf("%d
",f(n));
27     }
28     return 0;
29 }
View Code
原文地址:https://www.cnblogs.com/wuyuewoniu/p/4622746.html