码迷,mamicode.com
首页 > 其他好文 > 详细

【POJ1003】Hangover(二分抖索)

时间:2014-09-17 08:52:21      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   div   sp   

直接用库函数二分即可。

 

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <cstdio>
 5 #include <cmath>
 6 #include <cctype>
 7 #include <algorithm>
 8 #include <numeric>
 9 
10 #define eps 1e-8
11 using namespace std;
12 
13 double len[500];
14 
15 int main () {
16     ios :: sync_with_stdio(false);
17     len[0] = 0;
18     for (int i = 1; i < 300; ++ i) {
19         len[i] = len[i - 1] + 1.0 / (double)(i + 1);
20     }
21 
22     //cout << len[273] << endl;
23     double n;
24     while (cin >> n) {
25         if (n - 0 < eps) {
26             break;
27         }
28         //cout << lower_bound(len, len + 300, n) - &len[0] << endl;
29         printf ("%d card(s)\n", lower_bound(len, len + 300, n) - &len[0]);
30     }
31     return 0;
32 }

 

【POJ1003】Hangover(二分抖索)

标签:style   blog   color   io   os   ar   for   div   sp   

原文地址:http://www.cnblogs.com/Destiny-Gem/p/3976336.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!