18.2.14 codevs1011 数的计算

题目描述 Description

我们要求找出具有下列性质数的个数(包含输入的自然数n):

先输入一个自然数n(n<=1000),然后对此自然数按照如下方法进行处理:

1.          不作任何处理;

2.          在它的左边加上一个自然数,但该自然数不能超过原数的一半;

3.          加上数后,继续按此规则进行处理,直到不能再加自然数为止.

输入描述 Input Description

一个数n

输出描述 Output Description

满足条件的数的个数

样例输入 Sample Input

6

样例输出 Sample Output

6

数据范围及提示 Data Size & Hint

6个数分别是:

6

16

26

126

36

136

 1 #include <iostream>
 2 #include <math.h>
 3 #include<string.h>
 4 
 5 using namespace std;
 6 
 7 int sum=0;
 8 
 9 int sol(int n)
10 {
11     if(n<2)
12         return 0;
13     else
14     {
15         for(int i=1;i<=n/2;i++)
16         {
17             sum++;
18             sol(i);
19         }
20     }
21 }
22 
23 int main()
24 {
25     int n;
26     cin>>n;
27     sol(n);
28     cout<<sum+1<<endl;
29     return 0;
30 }
View Code

基础递推题

能帮助理解概念

注定失败的战争,也要拼尽全力去打赢它; 就算输,也要输得足够漂亮。
原文地址:https://www.cnblogs.com/yalphait/p/8448370.html