首页 > 代码库 > HDU 1592 Half of and a Half(大数)
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?
"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
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("\n"); 39 40 } 41 return 0; 42 }
HDU 1592 Half of and a Half(大数)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。