亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

POJ ACM習題【No.1003】

系統 2354 0
Hangover
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 42388 Accepted: 19686

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.


POJ ACM習題【No.1003】

Input

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.

Output

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)
  

?

解題思路:最小的張數就是大于總長度的第一個數字,注意使用浮點數。

?

?

    import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		String str;
		int maxCardNum = 0;
		
		while(cin.hasNext())
		{
			str = cin.nextLine();
			if(str.equals("0.00"))
				break;
			
			float len = Float.valueOf(str).floatValue();
			
			maxCardNum = getCardNum(len);
			System.out.println(maxCardNum + " card(s)");
		}

	}
	
	private static int getCardNum(float len)
	{
		float value = 0;
		int index = 2;
		
		while (value < len)
		{
			value += 1.0/index;
			index++;
		}
			
		return index-2;
	}

}

  
?

POJ ACM習題【No.1003】


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 一本久道热中字伊人 | 激情五月色婷婷丁香伊人 | 欧美日韩国产高清视频 | 国产精品午夜性视频 | 成人免费观看一区二区 | 水中色av综合 | 成年女人18级毛片毛片免费观看 | 欧美一区二区三区视频 | 亚洲国产网 | 国产精品嫩草研究所永久网址 | 欧美综合图区亚欧综合图区 | 亚洲精品国产成人专区 | 天天想天天干 | 九九热播视频 | 欧美特级一级毛片 | 欧美国产亚洲一区二区三区 | 天天射夜夜骑 | 老司机福利深夜亚洲入口 | 一区二区三区不卡免费视频97 | 久久久夜间小视频 | 日韩欧美理论片 | 国产精品久久久亚洲第一牛牛 | 99精品欧美一区二区三区美图 | 九九精品视频在线播放8 | 青青草免费在线视频 | 欧美人与动性xxxxbbbb | 日日夜夜操操操 | 综合图区亚洲白拍在线 | 91在线播 | 欧美一区二区三区婷婷月色 | 四虎永久免费紧急入口 | 精产网红自拍在线 | 欧美干干 | 日韩成 | 国产婷婷| 热er99久久6国产精品免费 | 日本aaaa| 在线观看欧美精品 | 一区在线播放 | 亚洲 欧美 自拍 卡通 综合 | 七七七久久久久人综合 |