poj 1003 Hangover

探讨如何利用不同数量的卡片实现特定长度的悬空效果,通过逐步叠加卡片并计算累积的悬空距离,找到达到指定悬空长度所需的最小卡片数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Hangover

Time Limit: 1000MS

Memory Limit: 10000K

Total Submissions: 84652

Accepted: 40731

Description

How far can you makea stack of cards overhang a table? If you have one card, you can create amaximum overhang of half a card length. (We're assuming that the cards must beperpendicular to the table.) With two cards you can make the top card overhangthe bottom one by half a card length, and the bottom one overhang the table bya third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 cardlengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) card lengths, where the top card overhangsthe second by 1/2, the second overhangs tha third by 1/3, the third overhangsthe fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.

 

悬在桌边的卡片,你能给摞多远?如果你有一长卡片,你可以最多用这个卡片的一半来覆盖这个桌子(我们假设这卡片必须与桌面垂直),对于邻近的两张卡片,你可以把一张覆盖到另一张上面,然后最底下的那一张覆盖桌子的1/3长度,总共覆盖了1/2+1/3=5/6卡片长度。通常情况下你可以用n张卡片覆盖1/2+1/3+1/4+…+1/(n+1)卡片长度,最顶端的覆盖1/2的长度,第二章覆盖1/3的长度,第三章覆盖1/4的,最后一张覆盖1/(n+1)。下面的图像举了一个实例。

Input

The inputconsists of one or more test cases, followed by a line containing the number0.00 that signals the end of the input. Each test case is a single linecontaining a positive floating-point number c whose value is at least 0.01 andat most 5.20; c will contain exactly three digits.

Output

For eachtest case, output the minimum number of cards necessary to achieve an overhangof at least c card lengths. Use the exact output format shown in the examples.

Sample Input

1.00

3.71

0.04

5.19

0.00

Sample Output

3 card(s)

61 card(s)

1 card(s)

273 card(s)

Source

Mid-Central USA 2001

 

Hangover

Time Limit: 1000MS

Memory Limit: 10000K

Total Submissions: 84652

Accepted: 40731

Description

悬在桌边的卡片,你能给摞多远?如果你有一长卡片,你可以最多用这个卡片的一半来覆盖这个桌子(我们假设这卡片必须与桌面垂直),对于邻近的两张卡片,你可以把一张覆盖到另一张上面,然后最底下的那一张覆盖桌子的1/3长度,总共覆盖了1/2+1/3=5/6卡片长度。通常情况下你可以用n张卡片覆盖1/2+1/3+1/4+…+1/(n+1)卡片长度,最顶端的覆盖1/2的长度,第二章覆盖1/3的长度,第三章覆盖1/4的,最后一张覆盖1/(n+1)。下面的图像举了一个实例。

 

Input

输入包含一组或者多组数据,0.00表示输入结束。每一组数据都是一行正实数c,c的范围在0.01和5.20之间;c由3个数字组成

Output

对于每一组数据,输出覆盖出来c的长度所需要的最少的卡片。就采用给出的输出例子的那种格式

Sample Input

1.00

3.71

0.04

5.19

0.00

Sample Output

3 card(s)

61 card(s)

1 card(s)

273 card(s)

Source

Mid-Central USA 2001

 

额,很水的题,就是用1/2+…1/n刚好比输入的数小就行,然后俺才知道如果输入用%llf。。。会t……..

 

#include<stdio.h>
#include<string.h>
#include<math.h>
 
void input(void);
 
int main(void){
   freopen("in.txt","r", stdin);
   input();
   return 0;
}
 
void input(void){
   double f, s;
   int i;
   while(scanf("%lf", &f) && (f > 0)){
       for (s = 0, i = 2;s < f;s += 1.0/i,i++);
       printf("%d card(s)\n", i-2);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值