Half of and a Half
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1139 Accepted Submission(s): 513
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?
"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;
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
Author
DYGG
Source
/*
HDU 1592靠,竟然是大数,刚才以为1000只是个什么小范围,2的1000+1次方啊
2^(n+1)-1,用大数怎么实现啊
高精度,貌似,好吧,,,
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[1005][105];
void System()
{
a[0][1] = 1;
for(int i = 1;i < 1005;i++)
{
for(int j = 1;j < 105;j++)
{
if(j == 1)
a[i][j] += a[i-1][j]*2 + 1;
else
a[i][j] += a[i-1][j]*2;
a[i][j+1] += a[i][j] / 10000;
a[i][j] = a[i][j] % 10000;
}
}
}
int main()
{
System();//高精度
int n;
while(~scanf("%d",&n))
{
int i,j;
for(i = 100;i >= 1;i--)
{
if(a[n][i])
{
printf("%d",a[n][i]);
break;
}
}
for(int j = i-1;j >= 1;j--)
printf("%04d",a[n][j]);
printf("\n");
}
return 0;
}