Can you solve this equation?
2015-07-30 23:20
253 查看
Can you solve this equation?
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 113 Accepted Submission(s) : 69
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!C语言程序代码/*
简单的二分法题,
*/
#include<stdio.h>
#include<math.h>
double f(double x)
{
return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
}
int main(){
int n,t,i;
double l,r,mid,y;
scanf("%d",&t);
while(t--)
{
scanf("%lf",&y);
if(y<f(0)||y>f(100))
printf("No solution!\n");
else
{
l=0;r=100;mid=0;
while(r-l>1e-10)
{
mid=(l+r)/2;
if(f(mid)-y>1e-10)
r=mid;
else
l=mid;
}
printf("%.4lf\n",r);
}
}
return 0;
}
相关文章推荐
- C++ 头文件相互包含的问题
- java 堆 栈 方法区的简单分析
- Fiddler捕捉ASP.NET WebSite调用WebService、WCF服务
- 扩展BaseAdapter实现不存储列表项的ListView
- JAVA设计模式——代理模式
- !HDU 5317 求区间里两个数的质因数个数的gcd的最大值-预处理
- eclipse的Toggle Block Selection Mode功能---列模式
- [2015-07-30] python011
- 数据挖掘领域十大经典算法初探
- mysql协议学习(一)——基本数据类型
- NOIP2010提高组--机械翻译
- DialogFragment 使用与友好交互
- java并发二
- 最近学习hadoop遇到的问题!虽然很小但是很恶心!同时求指教!!!
- this 关键字的应用
- MySql免安装版l配置方法
- Java操作串口
- Java操作串口 分类: Java 2015-07-30 23:18 11人阅读 评论(0) 收藏
- CSS常用布局实现方法
- java作业