HDU-2675 Equation Again
2015-07-26 15:22
561 查看
#include <iostream> #include <cmath> #include <cstdio> using namespace std; const double e = 2.718281828459; const double eps = 1e-7; int main() { double y; while(cin >> y) { double temp = log(e*y)/(e*y); double l = 0, r = e; while(r - l > eps) { double mid = (l + r) / 2; double ans = log(mid) / mid; if(ans >= temp) r = mid - eps; else l = mid; } if(fabs(y-1) > eps) printf("%.5f %.5f\n", r, e*y); else printf("%.5f\n", e*y); } return 0; }
题意:给这个公式X (eY) == (eY) x,Y值确定,求X的值。
题解:是水题 还是水题。然而我还是纠结了2个小时。(感谢阿信叠的友情出演..╮(╯▽╰)╭)一道数学题,然而脑残了..两边取对数,得:lnx / x = ln(ey) / (ey) 再对lnx / x求导,发现(0,e)单调递增,(e,+∞)单调递减。然而题目定y>=1,则ey>=e 。然后就这么陷进去了...........(当时想法 既然>=e,不就单调递减么 单调函数么,然后就x = ey 不就一一对应了么?还算什么,不就x = ey么?还什么二分查值)....现在回想...有点醉。跟阿信叠说歪理也一本正紧
他也陷进去了.... 然而ln(ey) /(ey),应该看做一整个常数,这样ey只是大于e的一个解 还有一个(0,e)的解。接下来只要取l = 0, r = e进行二分查值就好。这里是浮点数的二分查值,必须注意精度(eps)。还是得注意while(>) ,r = mid - ,l = mid。举个实例吧。一开始while(r - 1 > eps) r = mid - eps l =mid 输出 r +eps 是不过的。(注意只是>并不是>=)所以 应该只要输出r。(不需要+eps)(l也是不需要+eps的)。
总结浮点数形式应该是while(r - l > eps) if(>=) r = mid - eps;else l = mid ; pirntf(r); (尝试了 while(r - l >= eps) if(>=) r = mid - eps;else l = mid + eps; pirntf(r + eps)是错的)。
相关文章推荐
- 解决 httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0 错误
- 传苹果今年推iPad mini4 相当于微缩版Air2
- Project Euler:Problem 92 Square digit chains
- Airbnb Interview - Nested Integer List Parser
- ORA-12571: TNS:packet writer failure
- leetcode:Factorial Trailing Zeroes
- 1014. Waiting in Line (30)
- uva 10976 Fractions Again?!
- sgu297:Fair-play(水题)
- Scala入门到精通——第十一节 Trait进阶
- MyBaits一对一的查询方法
- 【ID搜索】uva529Addition Chains
- linux下C获取文件的大小http://blog.csdn.net/gdujian0119/article/details/6363574
- linux下如何用c语言调用shell命令http://blog.csdn.net/hzhsan/article/details/7989921
- Linux检测TCP连接断开的一种简单实现方法http://blog.csdn.net/wtewrw/article/details/6547380
- LoadRunner Controller阶段,脚本运行正常Passed Transactions 和Failed Transactions Errors 都没有数据显示?
- HDU 2674 N!Again【数学&&同余定理】
- 【Leetcode】 Factorial Trailing Zeroes #172
- rails总结
- rails总结