加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

杭电1592Half of and a Half(大数)

发布时间:2020-12-14 02:11:48 所属栏目:大数据 来源:网络整理
导读:Half of and a Half Time Limit: 1000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1023????Accepted Submission(s): 453 Problem Description Gardon bought many many chocolates from the A Chocolate Mar

Half of and a Half

Time Limit: 1000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1023????Accepted Submission(s): 453


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


大数题,题意是见一个人分总数的一半+0.5,最后正好没有,问总共有多少!


要想最后一个人正好分完,倒数第二个人分完后应剩下1,这样一半+0.5才正好为0;


所以大数u!


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
    int a[1100];
}s[1010];
int main()
{
    int i,j,t,n;
    s[0].a[0]=1;
    for(i=1;i<=1000;i++)
    {
        int r=0;
        for(j=0;j<1000;j++)
        {
            s[i].a[j]=s[i-1].a[j]*2+r;

            r=s[i].a[j]/10;

            s[i].a[j]%=10;

        }
        t=0;
        while(s[i].a[t]+1>9)
        {
            s[i].a[t]=0;
            t++;
        }
        s[i].a[t]+=1;
    }
    while(scanf("%d",&n)!=EOF)
    {
        for(i=999;i>=0,s[n].a[i]==0;i--);
        for(j=i;j>=0;j--)
            printf("%d",s[n].a[j]);
        printf("n");

    }
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读