您的位置:首页 > 其它

poj 1003 [离线预处理 + 二分]

2012-12-06 08:28 225 查看
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iterator>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!");
#define STOP system("pause");

using namespace std;
const int N = 300;
const double norm = 0.00000001;

int zero(double x) {
if(x < -norm) return -1;
return x > norm;
}

int main() {
double len
;
int total;
len[0] = 0.0;
for(total = 1; zero(len[total-1] - 5.20) <= 0; total++) {
len[total] = len[total - 1] + 1.0 / double(total + 1);
}
double x;
while(cin >> x, zero(x)) {
int l, r;
l = 0, r = total;
while(l <= r) {
int mid = MID(l, r);
if(zero(len[mid] - x) <= 0) {
l = mid + 1;
}
else r = mid - 1;
}
cout << r + 1 << " card(s)" << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: