第二专题 第三道题
来源:互联网 发布:小说 炫浪网络社区 编辑:程序博客网 时间: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
- 第二专题 第三道题
- 专题二 第二道题
- 专题四 第二道题
- 专题三 第二题
- 专题三 第三题
- 专题四 第三个题
- dp专题 第三题 采药
- 第三章第二题
- 第二章第三题
- 第二章第三题
- 第二章第三题
- 第二章第三题
- 第二章第三题
- 第二章第三题
- 第二章第三题
- 第二章第三题
- dp专题 第二题 最大子矩阵
- dp专题 第二十六题 滑雪
- LeetCode 103. Binary Tree Zigzag Level Order Traversal
- C++使用事件对象实现多线程
- Json解析库的使用
- Android Studio下的应用性能优化总结-内存优化
- Scala之旅-隐式转换
- 第二专题 第三道题
- MySql文件中My.ini的理解
- C++中extern “C”含义深层探索
- jquery 常用异步请求(ajax,post,get)和json对象的遍历
- 用多文件组织角色类
- 静静的说说USB TO TTL驱动的故事---For Windows7
- Fragment碎片的使用
- 关于运算符重载
- 设计模式学习--外观模式