• D


    D - Half of and a Half
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    Description

    Gardon bought many many chocolates from the A Chocolate Market (ACM). When he was on the way to meet Angel, he met Speakless by accident.
    "Ah, so many delicious chocolates! I'll get half of them and a half!" Speakless said.
    Gardon went on his way, but soon he met YZG1984 by accident....
    "Ah, so many delicious chocolates! I'll get half of them and a half!" YZG1984 said.
    Gardon went on his way, but soon he met Doramon by accident....
    "Ah, so many delicious chocolates! I'll get half of them and a half!" Doramon said.
    Gardon went on his way, but soon he met JGShining by accident....
    "Ah, so many delicious chocolates! I'll get half of them and a half!" JGShining said.
    .
    .
    .
    After had had met N people , Gardon finally met Angel. He gave her half of the rest and a half, then Gardon have none for himself. Could you tell how many chocolates did he bought from ACM?
     

    Input

    Input contains many test cases.
    Each case have a integer N, represents the number of people Gardon met except Angel. N will never exceed 1000;
     

    Output

    For every N inputed, tell how many chocolates Gardon had at first.
     

    Sample Input

    2
     

    Sample Output

    7
     1 #include<cstdio>
     2 #include<string.h>
     3 using namespace std;
     4 int ans[1000][510];
     5 int main()
     6 {
     7     //memset(ans,0,sizeof(ans));
     8     int n,i,j;
     9     while(scanf("%d",&n)!=EOF)
    10     {
    11 
    12         //i=300;
    13 memset(ans,0,sizeof(ans));
    14 ans[500]=1;
    15         while(n--)
    16         {
    17             int c=0;
    18             int s=0;
    19 
    20             for(i=500;i>=0;i--)
    21             {
    22                 if(i==500)
    23                  s=ans[i]*2+1+c;
    24                  else s=ans[i]*2+c;
    25                 ans[i]=s%10;
    26                 c=s/10;
    27 
    28             }
    29         }
    30         for(i=0;i<=500;i++) if(ans[i]!=0) break;
    31         j=i;
    32         for(j=i;j<=500;j++) printf("%d",ans[j]);
    33         printf("
    ");
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    MT【274】一道漂亮的不等式题
    MT【273】2014新课标压轴题之$ln2$的估计
    MT【272】更大的视野,更好的思路.
    MT【271】一道三角最值问题
    MT【270】含参绝对值函数最大之二
    MT【269】含参函数绝对值最大
    MT【268】投篮第一次很重要
    国内下载Git的连接地址
    django 取model字段的verbose_name值
    Django报错(NoReverseMatch at /admin/)
  • 原文地址:https://www.cnblogs.com/angledamon/p/3888186.html
Copyright © 2020-2023  润新知