NUC1003 Hangover【水题】

2023-10-21 17:10
文章标签 水题 nuc1003 hangover

本文主要是介绍NUC1003 Hangover【水题】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Hangover

时间限制: 1000ms 内存限制: 65536KB

问题描述

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

hangover.jpg

输入描述

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

输出描述

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

样例输入
1.00
3.71
0.04
5.19
0.00
样例输出
3 card(s)
61 card(s)
1 card(s)
273 card(s)
来源
{Mid-Central USA 2001}


问题分析:

这个题与《POJ1003 UVALive2294 HDU1056 ZOJ1045 Hangover》完全相同,代码直接拿过来用就AC了。

程序说明:

参见参考链接。

参考链接:POJ1003 UVALive2294 HDU1056 ZOJ1045 Hangover

题记:

程序写多了,似曾相识的也就多了。


AC的C++程序如下:

/* POJ1003 UVALive2294 HDU1056 ZOJ1045 Hangover */  #include <iostream>  
#include <cstdio>  using namespace std;  const double one = 1.0;  int main()  
{  double len, sum, d;  int i;  while((cin >> len) && len != 0.00) {  i = 1;  d = 2.0;  sum = one / d;  while(sum < len) {  d += 1.0;  sum += (one / d);  i++;  }  cout << i << " card(s)" << endl;  }  return 0;  
} 














这篇关于NUC1003 Hangover【水题】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/255776

相关文章

uva 10055 uva 10071 uva 10300(水题两三道)

情歌两三首,水题两三道。 好久没敲代码了为暑假大作战热热身。 uva 10055 Hashmat the Brave Warrior 求俩数相减。 两个debug的地方,一个是longlong,一个是输入顺序。 代码: #include<stdio.h>int main(){long long a, b;//debugwhile(scanf("%lld%lld", &

Codeforces Round #182 (Div. 2)A(水题)

题目链接:http://codeforces.com/contest/302/problem/A 解题思路: 只要通过重新排列使区间内和为0即是1,否则是0. 完整代码: #include <algorithm>#include <iostream>#include <cstring>#include <complex>#include <cstdio>#inc

HDU 2064 汉诺塔III(水题)

题目: http://acm.hdu.edu.cn/showproblem.php?pid=2064 题目大意: 有三根杆,求把n个圆盘从左边移到右边,最少需要移动圆盘的次数。移动规则为大盘不能放在小盘上,比原始的汉诺塔题改变的地方是,只能通过中间的杆往左右两边的杆移动。 心得: 此题心得在题外,不在题内,初看此题,尼玛吓了一跳,好像很难的样子,手贱百度了一下,只注意到俩字“水题”,赶紧

【SGU】115. Calendar 水题= =

传送门:【SGU】115. Calendar 题目分析:2001年1月1号星期1,然后就没什么好说的了= = 代码如下: #include <map>#include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespac

Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)

解题报告 意思就是说有n行柜子,放奖杯和奖牌,要求每行柜子要么全是奖杯要么全是奖牌,而且奖杯每行最多5个,奖牌最多10个。 直接把奖杯奖牌各自累加,分别出5和10,向上取整和N比较 #include <iostream>#include <cstdio>#include <cstring>#include <stdlib.h>#include <algorithm>

POJ 百炼 保研机试 1003:Hangover

1003:Hangover 查看提交统计提示提问 总时间限制:  1000ms  内存限制:  65536kB 描述 How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a ca

hdu 1013(水题)

题意:求一个数,各个数位相加,如果结果小于10则输出,否者递归进行数位相加。   #include <cstdio>#include <cstring>#include <string>#include <iostream>using namespace std;int result(int n){int sum = 0;while (n > 0){sum += n % 1

HDU 1008(水题)

题意:给一个数n,后跟着n个数,代表电梯要到的层数,如果是上升,则每层花费6分钟,下降每层划分4分钟,停着话费5分钟,求电梯总共花费多少时间。   #include <iostream>using namespace std;void main(){int n, m, t, total;while (cin >> n && n != 0){m = 0;total = 0;wh

HDU 1001(水题)

题意:输入n,求1~n之和。 import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner s=new Scanner(System.in);int n=0;int sum;while(s.hasNextInt()){sum=0;n=s.nextInt();

HDU 1000 (水题)

题意:输入两个整数,求两个整数的和。   #include <cstdio>int main(){int a, b;while (scanf("%d%d", &a, &b) != EOF){printf("%d\n", a+b);}}