UVa11384 Help is needed for Dexter
题目大意:给定正整数n,在序列[1 .. n]上每次可以选择任意一些数字将它们同时减去一个相同的正整数,求序列全部为0时最小操作次数。
题解:第一次从中间把右面的尽可能都切下来,然后就分解成了n/2的问题,然后递归搞。
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; int n; int f(int x) { return x == 1 ? 1 : f(x / 2) + 1; } int main() { while(scanf("%d", &n) == 1) { printf("%d\n", f(n)); } } ^C