hdu 2199 二分法求单调函数方程的解
2014-03-13 12:56
204 查看
首先,判断f(x)是单调递增的,wrong answer2次,因为在codeblock里运行的100的结果为1.6151(标准答案为1.6152),我用了四舍五入调为1.6152ws一次,后来修改了下很小值,将1e-7改为1e-4,调为1.6152,还是ws,最后不改提交后居然ac了。
#include<iostream>
#include<cmath>
#include<stdio.h>
#include<math.h>
using namespace std;
double f(double x)
{
return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
}
double Bi_Search(double y)
{
double left,right,mid;
left=0,right=100;
while(right-left>1e-6)
{
mid=(left+right)/2;
if(f(mid)<y)
{
left=mid+1e-7;
}
else right=mid-1e-7;
}
return (left+right)/2.0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
double y;
cin>>y;
if(y>=f(0)&&y<=f(100))
printf("%.4lf\n",Bi_Search(y));
else cout<<"No solution!"<<endl;
}
return 0;
}
#include<iostream>
#include<cmath>
#include<stdio.h>
#include<math.h>
using namespace std;
double f(double x)
{
return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
}
double Bi_Search(double y)
{
double left,right,mid;
left=0,right=100;
while(right-left>1e-6)
{
mid=(left+right)/2;
if(f(mid)<y)
{
left=mid+1e-7;
}
else right=mid-1e-7;
}
return (left+right)/2.0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
double y;
cin>>y;
if(y>=f(0)&&y<=f(100))
printf("%.4lf\n",Bi_Search(y));
else cout<<"No solution!"<<endl;
}
return 0;
}
相关文章推荐
- hdu 2199 解方程(二分法)
- HDU 2199 Can you solve this equation? (二分法解方程)
- hdu 2199 二分法求方程的根
- Constructing Roads In JGShining's Kingdom----HDU_1025----用二分法求最长单调子序列
- HDU-2199 二分搜索解方程
- 【二分解方程】hdu 2199 Can you solve this equation?
- HDU 2199(二分求方程解)
- HDU 2199 Can you solve this equation? 二分求方程解
- 二分法与黄金分割法求函数方程最小值
- hdu 2199 二分法-Can you solve this equation?
- hdu 2199~Can you solve the equation?~二分法求解
- uva10341 Solve It(二分法求单调方程的根)
- hdu 2199 Can you solve this equation?(二分查找方程的根)
- 【杭电2199】找方程的解 (二分法)
- HDU 2199 Can you solve this equation?(二分法求近似解)
- HD 2199 Can you solve this equation?【二分法求方程的解】
- HDU 2199 (二分法)
- NYOJ 503 & HDU 2199 解方程(二分)
- hdu 2199 Can you solve this equation?(二分法求多项式解)
- hdu 2199 Can you solve this equation? (二分法)