您的位置:首页 > 编程语言 > Go语言

POJ1003:Hangover

2013-03-10 21:57 483 查看
Description

Howfarcanyoumakeastackofcardsoverhangatable?Ifyouhaveonecard,youcancreateamaximumoverhangofhalfacardlength.(We'reassumingthatthecardsmustbeperpendiculartothetable.)Withtwocardsyoucanmakethetopcardoverhangthe
bottomonebyhalfacardlength,andthebottomoneoverhangthetablebyathirdofacardlength,foratotalmaximumoverhangof1/2+1/3=5/6cardlengths.Ingeneralyoucanmakencardsoverhangby1/2+1/3+
1/4+...+1/(n+1)cardlengths,wherethetopcardoverhangsthesecondby1/2,thesecondoverhangsthathirdby1/3,thethirdoverhangsthefourthby1/4,etc.,andthebottomcardoverhangsthetableby1/(n+
1).Thisisillustratedinthefigurebelow.



Input
Theinputconsistsofoneormoretestcases,followedbyalinecontainingthenumber0.00thatsignalstheendoftheinput.Eachtestcaseisasinglelinecontainingapositivefloating-pointnumbercwhosevalueisatleast
0.01andatmost5.20;cwillcontainexactlythreedigits.
Output
Foreachtestcase,outputtheminimumnumberofcardsnecessarytoachieveanoverhangofatleastccardlengths.Usetheexactoutputformatshownintheexamples.
SampleInput
1.00
3.71
0.04
5.19
0.00

SampleOutput
3card(s)
61card(s)
1card(s)
273card(s)


#include<stdio.h>

intmain()
{
intn;
floata,b;
while(~scanf("%f",&b),b)
{
a=0.0;
for(n=1;a<b;++n)
a+=1.0/(float)(n+1);
printf("%dcard(s)\n",n-1);
}

return0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: