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("\n");
34     }
35     return 0;
36 }

 

posted on 2014-08-03 11:07  Damonll  阅读(192)  评论(0编辑  收藏  举报