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 }
  • 相关阅读:
    osharp3引入事务后操作结果类别的调整
    Code First 迁移
    表达式拼接Expression<Func<IEntityMapper, bool>> predicate
    ASP.NET中Session的sessionState 4种mode模式
    EF Code First Migrations数据库迁移
    啊里大鱼短信发送API
    asp.net服务器控件的生命周期
    osharp3使用经验:整合DbContextScope 文章 1
    关于MarshalByRefObject的解释
    数据库操作事务IsolationLevel 枚举
  • 原文地址:https://www.cnblogs.com/angledamon/p/3888186.html
Copyright © 2011-2022 走看看