HDOJ 1056 HangOver(水题)

Problem Description
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’re 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.

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.

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)

英语不好真心看不懂(表示看不懂)。。。说了这么多,其实就是一个大水题。
公式题目给出了,就是求公式的和正好大于输入的n的时候的最小的整数。

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            double n = sc.nextDouble();
            if(n==0){
                return ;
            }
            int a=0;
            int t = 2;
            double sum=0;
            do{
                sum = sum+(1.0/t*1.0);
                a++;
                t++;
            }while(sum<n);
            System.out.println(a+" card(s)");
        }

    }

}
时间: 2024-10-23 16:34:21

HDOJ 1056 HangOver(水题)的相关文章

hdu 1056 HangOver 水题

HangOver             很水的一道题,无论是时间空间都约等于没有要求,直接模拟就可以过了. /* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <cstdio> int main() { double aim,now; int i; while(~scanf("%lf&

HDOJ 1070 Milk(水题,考英文的)

Problem Description Ignatius drinks milk everyday, now he is in the supermarket and he wants to choose a bottle of milk. There are many kinds of milk in the supermarket, so Ignatius wants to know which kind of milk is the cheapest. Here are some rule

HDOJ/HDU 1256 画8(绞下思维~水题)

Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一个整数,字符表示画笔,整数(>=5)表示高度. Output 画横线总是一个字符粗,竖线随着总高度每增长6而增加1个字符宽.当总高度从5增加到6时,其竖线宽度从1增长到2.下圈高度不小于上圈高度,但应尽量接近上圈高度,且下圈的内径呈正方形. 每画一个"8"应空一行,但最前和最后都无空

HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)

Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or the film of the same name by Stanley Kubrick. In it a spaceship is sent from Earth to Saturn. The crew is put into stasis for the long flight, only tw

HDOJ(HDU) 1555 How many days?(水题)

Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, k,(2 <= k <= M <= 1000).M = 0, k = 0代表输入结束. Output 对于每个测试实例输出一个整数,表示M元可以用的天数. Sample Input 2 2 4 3 0 0 Sample Output 3 5 水题.... import java.util.

HDOJ(HDU) 1859 最小长方形(水题、、)

Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内. Input 测试输入包含若干测试用例,每个测试用例由一系列坐标组成,每对坐标占一行,其中|x|和|y|小于 231:一对0 坐标标志着一个测试用例的结束.注意(0, 0)不作为任何一个测试用例里面的点.一个没有点的测试用例标志着整个输入的结束. Output 对每个测试用例,在1行内输出2对整数

HDOJ/HDU 2560 Buildings(嗯~水题)

Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, the green grids represent the buidings. Given the size of the HZNU Campus, and the color of each grid, you should count how many green grids in the N

字符-一道acm水题 all in all 一直找不出错误 求大神解答

问题描述 一道acm水题 all in all 一直找不出错误 求大神解答 描述字符串s和t均由字母组成,若在t中除去一些字母能够得到s,我们就说s是t的一个子串.比如abc就是acbefc的子串(acbefc去掉第二.第四.第五个字符后就得到abc)输入有若干组输入数据,每组一行,分别为字符串s和t,s与t之间用空格隔开输出对于一组s与t,若s是t的子串,则输出Yes,否则输出No 样例输入sequence subsequence abc acb VERDI vivaVittorioEmanu

HDU 1228 模拟水题

字符串的水题 用了两种方法做的 感觉做法都很山寨 题目很水 如果不限制小于100会很好   #include <iostream> #include<cstdio> #include<cstring> using namespace std; int pd(string s) { if(s=="zero") return 0; if(s=="one") return 1; if(s=="two") return