hdu 2199 Can you solve this equation?
来源:互联网 发布:网络爱国青年叫什么 编辑:程序博客网 时间:2024/06/06 16:27
Can you solve this equation?
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;
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
100
-4
Sample Output
1.6152
No solution!
解析:二分入门题,可以作为模板。
代码如下:
#include<iostream>#include<cstdio>#include<cmath>using namespace std;double f(double a){ return 8*pow(a,4.0)+7*pow(a,3.0)+2*pow(a,2.0)+3*a+6; //计算公式}int main(){ double b; int t; cin>>t; while(t--) { cin>>b; double i,j,m,n; if(f(0)<=b&&f(100)>=b) //二分条件 { m=0; n=100; while(n-m>1e-6) //精度取值 { i=(m+n)/2; //二分取段 double ans=f(i); //段位取值 if(ans>b) n=i-1e-7; //如果大于,则把左边的赋值二分位 else m=i+1e-7; //否则把右边的赋值二分位 } printf("%.4lf\n",(m+n)/2); } else cout<<"No solution!"<<endl; //否则输出无解 } return 0;}
0 0
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- HDU 2199-Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 can you solve this equation
- HDU 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation
- hdu-2199 Can you solve this equation?
- 计算机网络之面试常考
- JAVA的集合类(二)
- C语言之矩阵输入6*8的矩阵,求矩阵中值最大的那个元素的值已经其所在的行号和列号
- Linux下训练和测试自己的图片
- Arrays常用的方法(一部分)
- hdu 2199 Can you solve this equation?
- CSS设置图片的重复
- 前端面试题 - 如何居中一个float:left的元素
- iOS Swift 基础二
- Java 查找两个有复杂对象的集合中的不同元素和相同的元素
- Python学习记录1
- Shader特效——实现“HDR”效果【GLSL】
- 【Linux系统编程】进程间通信概述
- 一张图带你搞明白Dex文件格式