2013
12-12

# 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

#include<stdio.h>

#include<string.h>
int num[1010][1010];
int main()
{
int i,n,j;
memset(num,0,sizeof(num));
num[0][1]=1;
for(i=1;i<1010;i++)
{
for(j=1;j<1010;j++)
{
if(j==1)
num[i][j]+=(num[i-1][j])*2+1;
else
num[i][j]+=num[i-1][j]*2;
}
for(j=2;j<1010;j++)
{
if(num[i][j-1]>9)
num[i][j]+=num[i][j-1]/10;
num[i][j-1]%=10;
}
}
while(scanf("%d",&n)!=EOF)
{
for(i=1010;i>=1;i--)
if(num[n][i]!=0)
{
printf("%d",num[n][i]);
break;
}
for(j=i-1;j>=1;j--)
printf("%d",num[n][j]);
printf("\n");
}
return 0;
}

1. 其实国内大部分公司对算法都不够重视。特别是中小型公司老板根本都不懂技术，也不懂什么是算法，从而也不要求程序员懂什么算法，做程序从来不考虑性能问题，只要页面能显示出来就是好程序，这是国内的现状，很无奈。