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
SampleOutput
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;
}
相关文章推荐
- POJ1003 Hangover
- POJ1003_Hangover(二分求上界)
- POJ1003--Hangover 翻译
- 【poj1003】Hangover
- POJ1003 hangover
- poj1003 Hangover
- POJ1003--Hangover 翻译
- POJ1003:Hangover
- POJ1003-hangOver
- poj1003 Hangover
- [c] poj1003 hangover
- POJ1003 Hangover
- POJ1003,Hangover,数学题,题目看懂就没什么
- poj1003(Hangover)
- poj1003 -- Hangover
- poj1003(Hangover)
- Poj1003 Hangover
- poj1003 HangOver
- 二分法实战(一)——HangOver问题(POJ1003)
- poj1003 Hangover