Problem 1001
来源:互联网 发布:微视频神器软件 编辑:程序博客网 时间:2024/05/21 22:21
简单题意: 输入一个数Y,如果有一个数x(0<x<=100),使得8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,误差在1e-6以内,
解题思路:
用二分法求解,然后利用搜索求得最终解。
代码如下:
#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<cmath>
using namespace std;
#include<stdio.h>
#include<iomanip>
#include<cmath>
using namespace std;
double fun(double x)
{
return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6 ;
}
{
return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6 ;
}
double m(double x,double z, double y)
{
double mid;
while((y-z)>1e-10)
{
mid=(z+y)/2;
if(fun(mid)<x)
z=mid+1e-10;
else
y=mid-1e-10;
}
return mid;
}
{
double mid;
while((y-z)>1e-10)
{
mid=(z+y)/2;
if(fun(mid)<x)
z=mid+1e-10;
else
y=mid-1e-10;
}
return mid;
}
int main()
{
int n;
double a;
cin>>n;
while(n--)
{
cin>>a;
if(a<6||a>807020306||fabs(m(a,0,100))<1e-4)
cout<<"No solution!"<<endl;
else
cout<<fixed<<setprecision(4)<<m(a,0,100)<<endl;
}
return 0;
}
{
int n;
double a;
cin>>n;
while(n--)
{
cin>>a;
if(a<6||a>807020306||fabs(m(a,0,100))<1e-4)
cout<<"No solution!"<<endl;
else
cout<<fixed<<setprecision(4)<<m(a,0,100)<<endl;
}
return 0;
}
0 0
- Problem - 1001: Sum Problem
- Problem - 1001 Sum Problem
- Problem - 1001_Sum Problem
- Problem 1001
- Problem 1001
- problem-1001
- Problem 1001
- Problem-1001
- 【HDOJ】 <Problem - 1001> : Sum Problem
- 西安电子Problem 1001 A+B Problem
- ZOJ Problem Set - 1001||A + B Problem
- 1001 Problem B && 1008 Problem I
- 1001 A + B Problem
- 1001 Sum Problem.
- [HUD 1001]Sum Problem
- 1001 Sum Problem
- 1001 Sum Problem
- 1001:Sum Problem
- <css 八>border
- C++四则运算代码
- IAccessiable的学习和使用
- Hbase使用
- Android:inputType常用取值
- Problem 1001
- 新学JAVA二三事之字符串输出
- Java中Object有哪些公共类
- DOM基础
- java 集合
- Gaussian mixture model. EM VS variational inference
- 数学黑洞
- 解决android子控件与父控件滑动冲突的问题
- ns3使用doxygen生成离线api文档