zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    javascript:history.go()和History.back()的区别
    Web 开发] 定制IE下载对话框的按钮(打开/保存)(转)
    JavaScript 浮动定位提示效果(转)
    关于网页*静态化*及SEO问题的一些补充(转)
    httpanalyzer 结合 HttpWebRequest Post的运用
    SEO工具大全(转)
    导出excel
    Asp.NET导出Excel文件乱码解决若干方法 (转)
    关于DataBinder.Eval Eval Bind
    电脑疑似中毒
  • 原文地址:https://www.cnblogs.com/angledamon/p/3888186.html
Copyright © 2011-2022 走看看