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

杭电1592 Half of and a Half 大数

发布时间:2020-12-14 02:11:49 所属栏目:大数据 来源:网络整理
导读:Half of and a Half Time Limit: 1000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1022????Accepted Submission(s): 452 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): 1022????Accepted Submission(s): 452


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
?

Author
DYGG
?

Source
HDU “Valentines Day” Open Programming Contest 2007-02-14
?

Recommend
linle???|???We have carefully selected several similar problems for you:?? 1591? 1579? 1584? 1678? 1673?
?
公式很好推,2^(n+1)-1,附大数代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[1100][1100],i,j,k,l,m,n;
void ac()
{
	memset(a,sizeof(a));
	a[0][0]=1;
	for(i=1;i<1001+1;i++)
	{
		int flag=0;//进wei 
		for(j=0;j<1010;j++)
		{
			a[i][j]=a[i-1][j]*2+flag;
			flag=a[i][j]/10;
			a[i][j]%=10;
		}
	}
}
int main()
{
	ac();
	while(scanf("%d",&n)!=EOF)
	{
		for(i=1010-1;i>=0;i--)
		if(a[n+1][i])
		break;
		for(;i>0;i--)
		printf("%d",a[n+1][i]);
		printf("%dn",a[n+1][i]-1);//那么问题来了,为什么没有考虑最后一位为0 的情况 
	}//那样的话,就成大数减了,因为2的次方最后一位只会是2 4 8 6,还有一个1. 
}

(编辑:李大同)

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

    推荐文章
      热点阅读