概述
题目:求解
题意:给你Y的值,叫你求出X的值,根据公式8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y
思路:二分法
感想:基础的二分法题
代码:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#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;
}
int main()
{
double mid,r,l;
double y;
int t;
cin>>t;
while(t--)
{
cin>>y;
if(f(0)>y||f(100)<y)
{
cout<<"No solution!"<<endl;
}
else
{
l=0;
r=100;
while(r-l>1e-9)
{
mid=(r+l)/2;
if(f(mid)>y) r=mid;
else l=mid;
}
printf("%.4lfn",mid);
}
}
return 0;
}
最后
以上就是精明吐司为你收集整理的练习2————1001的全部内容,希望文章能够帮你解决练习2————1001所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复