题目大意:给定正整数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
本文介绍了一种求解在序列[1..n]上,通过每次选择并减少相同正整数的方式,使序列全部变为0所需的最小操作次数的算法。核心思路是从中间分割序列,递归解决子问题。
459

被折叠的 条评论
为什么被折叠?



