二分搜索--控制精度--hdu2199 Can you solve this equation
来源:互联网 发布:精灵虚拟光驱激活mac 编辑:程序博客网 时间:2024/05/21 07:10
1.要求4位小数,精度可以开得更高些
2.可以取得到的一般r - l >= eps,有等号
3.r = mid - eps,l = mid + eps往2边都取eps
4.最后退出的时候仍然取mid,(l + r) / 2;
#include <iostream>
#include <cstdio>
#include <cmath>
using namespacestd;
const double eps =1e-6;
double y;
double equation(double x)
{
return (((8 * x +7) * x + 2) * x +3) * x + 6;
}
void solve(double y)
{
if (y <6.0 || y > equation(100.0)) {
printf("No solution!\n");
return;
}
double l =0.0,r = 100.0;
double mid =0;
while (r - l >=eps) {
mid = (l + r) / 2;
if(equation(mid) > y)
r = mid - eps;
else l = mid +eps;
}
printf("%.4lf\n",(l + r) /2);
}
int main()
{
int T;
cin >> T;
while (T --) {
scanf("%lf",&y);
solve(y);
}
return0;
}
- 二分搜索--控制精度--hdu2199 Can you solve this equation
- hdu2199 Can you solve this equation? (二分+double精度)
- hdu2199 Can you solve this equation? (二分搜索)
- HDU2199:Can you solve this equation?(二分)
- HDU2199 Can you solve this equation?(二分)
- (二分,精度控制)Can you solve this equation?--HDOJ
- Can you solve this equation?【二分】+【精度】
- hdu2199 Can you solve this equation?(二分)
- 【hdu2199】Can you solve this equation?——二分
- HDU2199:Can you solve this equation?(数学 + 二分)
- ACM-二分搜索之Can you solve this equation?——hdu2199
- HDU2199 Can you solve this equation?
- hdu2199 Can you solve this equation?
- HDU2199 Can you solve this equation?
- hdu2199 Can you solve this equation?
- hdu-2199 Can you solve this equation?(二分+精度)
- HDU—2199—Can you solve this equation?—【二分】【精度控制】
- (step4.1)hdu2199(Can you solve this equation?——二分查找)
- 牛客剑指offer刷题笔记
- Android Telephony分析(五)--- TelephonyRegistry 详解
- javascript异步和单线程
- java后台开发Hibernate例子--登录查询
- hpu暑假训练 E: YK的书架【思维】
- 二分搜索--控制精度--hdu2199 Can you solve this equation
- 老司机手把手教你自己编译jdk
- WIN32 控件显示RGB 图像 / Mat 图像
- ubuntu rebar3 安装
- SSH框架的初步搭建
- js数组的迭代器方法(some、every、forEach、map、filter)
- Common sense for server
- bzoj1222 [HNOI2001]产品加工(dp)
- 智能指针的发展史