pku oj overhang叠加卡片求最少的卡片数
这个估计是里面第二简单的了,因为第一简单的是求a+b
哈哈,一submit就ac了
题目如下:
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.
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)
简单的归结就是一个级数求和的问题
#include <iostream>
using namespace std; class Overhang {
private:
double a;
public:
int getCardsNum();
void getValue() { cin >> a; }
double geta() { return a; }
}; int Overhang::getCardsNum() {
int num=1;
double sum=0.0;
while(true) {
sum += 1.0/(num+1);
num++;
if (sum >= a)
return --num;
}
}
int main(void) {
Overhang t;
while(true) {
t.getValue();
if ((t.geta() - 0.0) < 0.0001)
return 0;
cout << t.getCardsNum() << " card(s)" << endl;
}
}
pku oj overhang叠加卡片求最少的卡片数的更多相关文章
- Counting Kangaroos is Fun 求最少可见袋鼠数
Description There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaro ...
- HDU 1326 Box of Bricks(水~平均高度求最少移动砖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1326 题目大意: 给n堵墙,每个墙的高度不同,求最少移动多少块转使得墙的的高度相同. 解题思路: 找到 ...
- poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】
Road Construction Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10141 Accepted: 503 ...
- 输入一个数字n 如果n为偶数则除以2,若为奇数则加1或者减1,直到n为1,求最少次数 写出一个函数
题目: 输入一个数字n 如果n为偶数则除以2,若为奇数则加1或者减1,直到n为1,求最少次数 写出一个函数 首先,这道题肯定可以用动态规划来解, n为整数时,n的解为 n/2 的解加1 n为奇数时 ...
- PKU OJ 1002 487-3279
PKU OJ 1002 487-3279 487-3279 Description Businesses like to have memorable telephone numbers. One w ...
- [Leetcode 216]求给定和的数集合 Combination Sum III
[题目] Find all possible combinations of k numbers that add up to a number n, given that only numbers ...
- 我的第一篇博客:不用sizeof求int的bit数
我的第一篇博客.. 还不会什么高端的东西就来点基础的. 不用sizeof求int的bit数 //不用sizeof求int的bit数 #include<stdio.h> int main( ...
- hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。
题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...
- java笔试之求最大连续bit数
功能: 求一个byte数字对应的二进制数字中1的最大连续数,例如3的二进制为00000011,最大连续2个1 输入: 一个byte型的数字 输出: 无 返回: 对应的二进制数字中1 ...
随机推荐
- idea中pom.xml关于oracle配置
由于Oracle授权问题,Maven3不提供Oracle JDBC driver,为了在Maven项目中应用Oracle JDBC driver,必须手动添加到本地仓库. Orace驱动的下载:htt ...
- HDUOJ----专题训练C
Problem C Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- iOS中的#import和class区别
在ios中我们经常会在.h和.m中引入一些类啊等等一般用的是#import来进行声明,你们可能也见到在.h文件进用@class来声明的,那么#import和@class进行声明 到底有什么的区别呢?下 ...
- linux常见面试题及答案
1. 在Linux系统中,以文件方式访问设备. 2. Linux内核引导时,从文件/etc/fstab中读取要加载的文件系统. 3. Linux文件系统中每个文件用i字节来标识. 4. 全部磁盘块由四 ...
- 设置当前Activity的屏幕亮度
设置当前的Activity的屏幕亮度,而不是设置系统的屏幕亮度,退出当前的Activity后恢复系统的亮度. 直接看代码好了 Java代码 WindowManager.LayoutParams lp ...
- Spring3 MVC请求参数获取的几种方法[转]
Spring3 MVC请求参数获取的几种方法 Spring3 MVC请求参数获取的几种方法 一. 通过@PathVariabl获取路径中的参数 @RequestMapping(value=& ...
- android 登陆界面
LoginActivity.java package com.example.ruian; import android.app.Activity; import android.app.AlertD ...
- RHCE7 管理I-12归档文件并在Linux系统间复制文件
tar命令使用 默认tar只有归档的功能,没有压缩功能 tar [option...] [file]... -c,--create 创建 -x,--extract,--get 解压 -t, ...
- 进程控制块PCB结构 task_struct 描述
注:本分类下文章大多整理自<深入分析linux内核源代码>一书,另有参考其他一些资料如<linux内核完全剖析>.<linux c 编程一站式学习>等,只是为了更好 ...
- jQuery attr方法修改onclick值
了通过jQuery的attr修改onclick值. 代码: var js = "alert('B:' + this.id); return false;"; var newclic ...