Half of and a Half
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 792 Accepted Submission(s): 350
"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?
Each case have a integer N,represents the number of people Gardon met except Angel. N will never exceed 1000;
2
7
递推+大数处理
#include<iostream>
using namespace std;
int a[100];
int main() { int n,i,j,temp; int len; while(scanf("%d",&n)!=EOF) { memset(a,sizeof(a)); len=0; a[len]=1; for(i=1;i<=n;i++) { temp=0; for(j=0;j<=len;j++) { if(j==0) a[j]=(a[j]+0.5)*2; else a[j]=a[j]*2+temp; temp=a[j]/10000; a[j]=a[j]%10000; } if(temp) { len++; a[len]=temp; } } printf("%d",a[len]); for(i=len-1;i>=0;i--) printf("%04d",a[i]); printf("\n"); } return 0; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。