zoukankan      html  css  js  c++  java
  • codevs1011 数的计算 2001年NOIP全国联赛普及组

    题目描述 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 <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <cctype>
     6 #include <cstdlib>
     7 #include<cmath>
     8 #include <string>
     9 #include <map>
    10 #include <set>
    11 #include <queue>
    12 #include <vector>
    13 #include <stack>
    14 #include <cctype>
    15 using namespace std;
    16 typedef unsigned long long ull;
    17 #define INF 0xfffffff
    18 
    19 //0:1;1:1;2:2;3:2;
    20 
    21 int main()
    22 {
    23     int T;
    24     int a[1000],b;
    25     while(cin>>b)
    26     {
    27         memset(a,0,sizeof(a));
    28         a[0]=1;a[1]=1;
    29         for(int i=2;i<=b;++i)
    30             for(int j=0;j<=i/2;++j)
    31                 a[i]+=a[j];
    32         cout<<a[b]<<endl;
    33     }
    34 
    35     
    36     return 0;
    37 }
  • 相关阅读:
    vim高亮
    mengning
    4.4内核osal
    tmpvalgrind
    为什么引入协程
    alloc_call_show(转)
    TSAN
    如何查看哪些进程占用Buffer和Cache高(转)
    ASAN详解其他参考链接
    Linux系统与程序监控工具atop教程(转)
  • 原文地址:https://www.cnblogs.com/Traveller-Leon/p/4896835.html
Copyright © 2011-2022 走看看