[POJ1003]Hangover

试题描述

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.

输入示例

1.00
3.71
0.04
5.19
0.00

输出示例

 card(s)
card(s)
card(s)
card(s)

数据规模及约定

见“输入

题解

先预处理一下 S[k] = 1/1 + 1/2 + 1/3 + ... + 1/k 的前缀和,因为输入最多是 5.20,看到样例非常良心,所以应该不会比 273 大多少,我就预处理了前 100 个。

每个询问二分答案就好了。(或者直接扫一遍也能过)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 1010
double S[maxn]; int main() {
for(int i = 1; i <= maxn - 10; i++) S[i] = S[i-1] + 1.0 / (double)(i + 1); while(1) {
double x;
scanf("%lf", &x);
if(x == 0.0) break;
int l = 1, r = 1000;
while(l < r) {
int mid = l + r >> 1;
if(S[mid] < x) l = mid + 1; else r = mid;
}
printf("%d card(s)\n", l);
} return 0;
}

[POJ1003]Hangover的更多相关文章

  1. POJ1003 – Hangover (基础)

    Hangover   Description How far can you make a stack of cards overhang a table? If you have one card, ...

  2. POJ-1003&1004

    这两题比较简单,就不做分析了,描述下题目,就上代码吧. [题目描述] 1003,其实就是求这个方程的最小n:1/2 + 1/3 + 1/4 + ... + 1/(n + 1) >= c: 100 ...

  3. Hangover[POJ1003]

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 121079   Accepted: 59223 Descr ...

  4. 【POJ1003】Hangover(二分搜索)

    直接用库函数二分即可. #include <iostream> #include <cstring> #include <cstdlib> #include < ...

  5. poj 1003:Hangover(水题,数学模拟)

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 Descri ...

  6. HangOver

    HangOver Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  7. Hangover 分类: POJ 2015-06-11 10:34 12人阅读 评论(0) 收藏

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 108765   Accepted: 53009 Descr ...

  8. HDU1056 HangOver

    HangOver Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descript ...

  9. [POJ] #1003# Hangover : 浮点数运算

    一. 题目 Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 116593   Accepted: 56886 ...

随机推荐

  1. Windows下apache php wordpress配置

    2. Use notepad to open httpd.conf config file. Make use the line "LoadModule rewrite_module mod ...

  2. JS表单学习笔记(思维导图)

    导图

  3. 【Moqui业务逻辑翻译系列】Shipment Receiver Receives Shipment with Packing Slip but no PO

    Shipment Receiver receives shipment. It has invoice tucked into it. Receiver records vendor name, ve ...

  4. [Linux主机] 优化你的php-fpm(php5.3+)让你的网站跑得更快

    从php5.3以后php自带了php-fpm不是和php5.2一样以插件的方式存在了.这给我们带来一个好处502没有那么容易出现了坛子里用linux的绝大多数应该还是在用小军的lnmp的那个包,但是配 ...

  5. nginx 的源码安装

    安装nginx之前要做的准备工作有:安装如下库 (1)gzip模块需要 zlib 库 (2)rewrite模块需要 pcre 库 (3)ssl 功能需要openssl库 还有一种简单的方法就是 yum ...

  6. C基础--初学指针

    一.指针简介(任何指针变量在内存中占八个字节的存储空间) 1.定义指针变量(格式):变量类型 *变量名:--定义一个指向整形变量的指针  int *p; 2.作用:指针变量就是用来存储其他变量的地址: ...

  7. Java算法-符号&

     &与运算符 与运算符用符号“&”表示,其使用规律如下:两个操作数中位都为1,结果才为1,否则结果为0 例如下面的程序段. public class data13 { public s ...

  8. sql-数据库的隔离级别

    read uncommited  (读未提交)      最低级别,可读取未提交事物的数据,这会导致脏读,比如:某时刻会话a修改了一个数据,但还未提交,此时会话b,读取了该数据,这是,会话a回滚了事物 ...

  9. std::ios::sync_with_stdio(false);

    这句语句是用来取消cin的同步,什么叫同步呢?就是iostream的缓冲跟stdio的同步.如果你已经在头文件上用了using namespace std;那么就可以去掉前面的std::了.取消后就c ...

  10. 38.Android之ListView简单学习(一)

    android中ListView用的很普遍,今天来学习下,本篇主要以本地数据加载到listview,后面会学习从网络获取数据添加到listview. 首先改下布局文件: <?xml versio ...