day2 HDU 2199 Can you solve this equation?
来源:互联网 发布:淘宝直通车点击 编辑:程序博客网 时间:2024/06/15 03:27
#include"iostream"#include"iomanip"#include"math.h"using namespace std;double f(double x){ return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;}double find(double y){ double l,r,mid,k; l=0; r=100; mid=(l+r)/2.0; k=f(mid); while(fabs(k-y)>0.00001) { if(k>y)r=mid; else l=mid; mid=(l+r)/2.0; k=f(mid); } return mid;}int main(){ int t; double y,k; cin>>t; while(t--) { cin>>y; if(f(0)>y||f(100)<y) cout<<"No solution!"<<endl; else { cout<<fixed<<setprecision(4)<<find(y)<<endl; } } return 0;}
求解方程问题,要注意精度的设置,至少要达到和样例相同的答案精度
除此之外,在第一次尝试的时候,二分判断条件写的是l+esp<r这种,后来交上去WA,以区间带精度划分结果可能会导致结果不正确,对于直接二分求答案的题目还是将答案带精度是否在误差允许范围内作为判断条件比较好
0 0
- day2 HDU 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- HDU 2199-Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 can you solve this equation
- HDU 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation
- [李景山php]thinkphp核心源码注释|Apc.class.php
- poj 3278 || hdu2717 Catch That Cow 人生第一道BFS
- 简单功能强大的jQuery图片剪裁插件Image Cropper
- [李景山php]thinkphp核心源码注释|Db.class.php
- 2.IOS>UI>UIView
- day2 HDU 2199 Can you solve this equation?
- HDU 5098 Smart Software Installer(拓扑排序+贪心)
- Centos6.6中LAMP的安装
- Android--长按菜单--ContextMenu
- Android 主题层级
- 【NYOJ】[144]小珂的苦恼
- HDU1856
- Acm 62 笨小熊
- HDU 2563 统计问题