第二专题 第三道题

来源:互联网 发布:小说 炫浪网络社区 编辑:程序博客网 时间:2024/05/19 18:14

1.题目编号:1001

2.简单题意:知道一个公式8*x^4+7*x^3+2*x^2+3*x+6=y,给定T组数据,每组数据中给出y值,让求x。且y大于等于x等于0小于等于x等于100

3.解题思路形成过程:看到这道题就会想到数太大,容易超时,而且他给出了x的取值范围,所以选择二分法将其解答出来,需要注意的是最后题目要求小数点后保留4位

4.感悟:虽然学习的是广度还有深度搜索,但是学习没有界限,经常温故一下所学的知识也不错

5AC的代码:

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
double found(double x)
{
 return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
}
int main()
{
 int T;
 double y,mid;
 cin>>T;
 while(T--)
 {
  cin>>y;
  if(found(0)>y||found(100)<y)
  {
   cout<<"No solution!"<<endl;
  }
  else
  {
   double l=0,r=100;
   while(r-l>1e-10)
   {
    mid=(r+l)/2;
    if(found(mid)>y)
     r=mid;
    else
    l=mid;
   }
   printf("%.4lf\n",mid);
  }
 }
 return 0;
}

原题:

Problem Description


Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and 100;<br>Now please try your lucky.


 


Input


The first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has a real number Y (fabs(Y) <= 1e10);


 


Output


For each test case, you should just output one real number(accurate up to 4 decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between 0 and 100.


 


Sample Input


2<br>100<br>-4<br>


 


Sample Output


1.6152<br>No solution!<br>


 



0 0
原创粉丝点击