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; }
相关文章推荐
- poj1003预处理+二分查找
- POJ 3601 Escape from Enemy Territory (二分+BFS+预处理)
- poj 2112 Optimal Milking 【最大流 简单题】 【floyd预处理最短路 + 二分 + 最大流】
- Poj 1358 Housing Complexes【二分匹配+二维前缀和预处理建图】
- POJ 2761 树状数组+二分+离线
- poj 3501 Escape from Enemy Territory 预处理+二分+bfs
- POJ 2112—— Optimal Milking——————【多重匹配、二分枚举答案、floyd预处理】
- 每日三题-Day1-A(POJ 1358 Housing Complexes 预处理+二分匹配)
- POJ1003 二分_查找/自定义zero()函数
- poj 1338 Ugly Numbers [ 离线预处理 - 只处理丑数,复杂度很低 此题也是 程序猿的经典面试题]
- POJ 1003 Hangover(二分搜索)
- poj 5024&&&2014 ACM/ICPC Asia Regional Guangzhou Online 1003(预处理)
- poj 2739 [离线预处理 + 枚举]
- POJ 3110 Jenny's First Exam (二分 + 树状数组 + 贪心 + 预处理年份)
- poj 1003 Hangover 二分查找不大于x的最大值
- poj_3294 Life Forms(后缀数组+二分)
- POJ 2112 Optimal Milking (二分+最短路径+网络流)
- POJ 2112.Optimal Milking【Floyd+二分+最大流】
- 【最大流+Dinic+Edmonds_Karp+二分匹配】北大 poj 1698 Alice's Chance
- POJ 1003