HDU 1592 Half of and a Half(大数)

时间:2023-03-10 00:25:12
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
 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
int a[];
}s[];
int main()
{
int i,j,t,n;
s[].a[]=;
for(i=;i<=;i++)
{
int r=;
for(j=;j<;j++)
{
s[i].a[j]=s[i-].a[j]*+r; r=s[i].a[j]/; s[i].a[j]%=; }
t=;
while(s[i].a[t]+>)
{
s[i].a[t]=;
t++;
}
s[i].a[t]+=;
}
while(scanf("%d",&n)!=EOF)
{
for(i=;i>=,s[n].a[i]==;i--);
for(j=i;j>=;j--)
printf("%d",s[n].a[j]);
printf("\n"); }
return ;
}