二分搜索 HDOJ 2675 Equation Again
2015-07-25 18:23
525 查看
题目传送门
/* 二分搜索:式子两边取对数,将x提出来,那么另一边就是一个常数了,函数是:lnx/x。二分搜索x,注意要两次 */ #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const double e = exp (1.0); double cal(double x) { return log (x) / x; } int main(void) { //HDOJ 2675 Equation Again //freopen ("HDOJ_2675.in", "r", stdin); double y, k; while (scanf ("%lf", &y) == 1) { k = (1 + log (y)) / (e * y); //if (k > 1 / e) { //囧! // puts ("Happy to Women’s day!"); continue; //} if (k == 1 / e) { printf ("%.5f\n", e); continue; } double x1, x2; double l = 0, r = e; for (int i=1; i<=100; ++i) { double mid = (l + r) / 2; if (cal (mid) >= k) r = mid; else l = mid; } x1 = l; l = e, r = 1e9; for (int i=1; i<=100; ++i) { double mid = (l + r) / 2; if (cal (mid) >= k) l = mid; else r = mid; } x2 = l; printf ("%.5f %.5f\n", x1, x2); } return 0; }
相关文章推荐
- 模拟器报Installation error: INSTALL_FAILED_CONTAINER_ERROR解决方法
- hdoj 2647 N!Again
- 人工智能的策略,如果国家优先发展”梦想成真”?
- Linux中的文件描述符与打开文件之间的关系 :http://blog.csdn.net/cywosp/article/details/38965239
- 关于Flash中的黑白棋AI编写心得
- Snail—OC学习之类别Category
- [leetcode ]220.Contains Duplicate III
- Snail—OC学习之空变量的表示
- Snail—OC学习之NSNumber
- Snail—OC学习之日期NSDate
- UVa 11853 - Paintball(DFS)
- HDU 1302 The Snail
- http://blog.csdn.net/ooflywing/article/details/5616311
- HDU 2674-- N!Again【技巧】
- 最具体的历史centos下一个 postfix + extmail + dovecot + maildrop 安装注意事项2014更新
- HDU 5289 2015 Multi-University Training Contest 1 1002 RMQ+二分
- hdoj 2674 N!Again 【好题】
- Leetcode 11 Container With Most Water
- uva12546. LCM Pair Sum
- HDU 2473 Junk-Mail Filter (并查集的删除操作)