WOJ1142-Half of and a Half

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 contains many test cases.
Each case have a integer N, represents the number of people Gardon met except Angel. N will never exceed 1000;

输出格式

For every N inputed, tell how many chocolates Gardon had at first.

样例输入

2

样例输出

7

ans[i]=ans[i-1]*2+1,需要大数。

#include<stdio.h>
#include<string.h>
int res[320],w;
void cal(){
	int i,flag=0;
	if(res[0]>=5){
		res[0]=2*res[0]%10+1;
		flag=1;
	}
	else{
		res[0]=2*res[0]+1;
		flag=0;
	}
	for(i=1;i<w;i++){
		if(res[i]>=5){
			res[i]=2*res[i]%10+flag;
			flag=1;
		}
		else{
			res[i]=2*res[i]+flag;
			flag=0;
		}
	}
	if(flag==1){
		res[w]=1;
		w++;
	}
}
int main(){
    int n,i;
    while(scanf("%d",&n)==1){
    	memset(res,0,sizeof(res));
    	res[0]=1;w=1;
    	for(i=n;i>0;i--)
    	cal();
    	for(i=w-1;i>=0;i--)
		printf("%d",res[i]);
		printf("\n");
	}
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值