zoukankan      html  css  js  c++  java
  • HDU 1592 Half of and a Half(大数)

    Half of and a Half

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1179    Accepted Submission(s): 539


    Problem 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<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 struct node
     6 {
     7     int a[1100];
     8 }s[1010];
     9 int main()
    10 {
    11     int i,j,t,n;
    12     s[0].a[0]=1;
    13     for(i=1;i<=1000;i++)
    14     {
    15         int r=0;
    16         for(j=0;j<1000;j++)
    17         {
    18             s[i].a[j]=s[i-1].a[j]*2+r;
    19 
    20             r=s[i].a[j]/10;
    21 
    22             s[i].a[j]%=10;
    23 
    24         }
    25         t=0;
    26         while(s[i].a[t]+1>9)
    27         {
    28             s[i].a[t]=0;
    29             t++;
    30         }
    31         s[i].a[t]+=1;
    32     }
    33     while(scanf("%d",&n)!=EOF)
    34     {
    35         for(i=999;i>=0,s[n].a[i]==0;i--);
    36         for(j=i;j>=0;j--)
    37             printf("%d",s[n].a[j]);
    38         printf("
    ");
    39 
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    数论知识点整理
    《STL 源码剖析》 list 实现原理
    《STL 源码剖析》 vector 实现原理
    用户偏爱曲风分析(二)
    C++ 静态库 与 动态库
    用户偏爱曲风分析(一)
    C++ 编程中 的性能问题
    《C++API 设计》4.6 类设计
    《C++ API设计》 4.5 架构设计
    Boost 时间库使用 笔记
  • 原文地址:https://www.cnblogs.com/Annetree/p/6291875.html
Copyright © 2011-2022 走看看