荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: kaman (天外飞仙), 信区: ACMICPC
标 题: [合集]我有道题请帮我看看我写的哪里错了?
发信站: 荔园晨风BBS站 (Tue Jun 1 11:23:40 2004), 站内信件
bakey (深海的鱼爱上会潜水的猫) 于Sun May 30 21:46:57 2004提到:
Tomorrow is Kate's birthday, Kate is a lovely girl aged 20. This
Contest is held for her birthday and I want everyone will be happy
today. My name is sea .I'm not so good at English and Programming. But
when I know that it is possible to have a personal contest on JOJ. I
want to have a try. Just for her.
Kate : Wish you beauty and healthy forever
happy birthday!
Do you know the game "Towers of Hanoi"? It is a very famous game. But
people stopped moving discs from peg to peg after they know the number
of steps needed to complete the entire task ! Kate loves the game.
She want to know how many times she has to move the disks at least to
complete the game?
As we all know , for n disks the game takes 2^n-1 moves at least. But
kate want to know the exact numble. Sea want to tell her ,but he is poor
at math. So he want to write a program to help her.
Input Specification
Each line contains a numbe 'N' (0 <= N <= 500). N stand for the number
of the disks.
Output Specification
Just output the least time that kate has to move the disks to complete
the game. one per line.
Sample Input
7
10
Sample Output
127
1023
bakey (深海的鱼爱上会潜水的猫) 于Sun May 30 21:47:36 2004提到:
我的代码
#include <stdio.h>
#include <string.h>
void pow(int n)
{
int i,j,flag=0;
int m=199;
int sum[1000];
memset(sum,0,sizeof(sum));
sum[999]=2;
for (i=0;i<n-1;i++)
{
for (j=999;j>=0;j--)
{
if (flag==1)
{
sum[j]=sum[j]*2+1;
flag=0;
if (sum[j]>=10)
{
sum[j]-=10;
flag=1;
}
}
else
{
sum[j]*=2;
if (sum[j]>=10)
{
sum[j]-=10;
flag=1;
}
}
}
}
for (j=0;j<=999;j++)
{
if (sum[j]!=0)
break;
}
sum[999]--;
for (i=j;i<=999;i++)
printf("%d",sum[i]);
printf("\n");
}
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
pow(n);
}
return 0;
}
alec (AlecMonkeyKing) 于Sun May 30 21:53:13 2004提到:
reading wait
alec (AlecMonkeyKing) 于Sun May 30 21:57:46 2004提到:
#include <stdio.h>
#include <string.h>
void pow(int n)
{
int i,j,flag=0;
int m=199;
int sum[1000];
if (n==0)
{
printf("%d\n",0);
return;
}
memset(sum,0,sizeof(sum));
sum[999]=2;
for (i=0;i<n-1;i++)
{
for (j=999;j>=0;j--)
{
if (flag==1)
{
sum[j]=sum[j]*2+1;
flag=0;
if (sum[j]>=10)
{
sum[j]-=10;
flag=1;
}
}
else
{
sum[j]*=2;
if (sum[j]>=10)
{
sum[j]-=10;
flag=1;
}
}
}
}
for (j=0;j<=999;j++)
{
if (sum[j]!=0)
break;
}
sum[999]--;
for (i=j;i<=999;i++)
printf("%d",sum[i]);
printf("\n");
}
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
pow(n);
}
return 0;
}
alec (AlecMonkeyKing) 于Sun May 30 21:58:12 2004提到:
just a little problem of the input 0
bakey (深海的鱼爱上会潜水的猫) 于Sun May 30 22:05:20 2004提到:
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店