Can you solve this equation?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 25633    Accepted Submission(s): 11018

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!

题意:知道y值,要求算出x。并且x只能在0~100之间,不然就输出No solution!

题解:因为x只能在0~100之间。所以在知道y值得情况下判断有没有解的方法是:如果给出的Y值比f(0)还小,那他肯定没有0~100之间的解。因为解在0~100之间都是正数。同理也不能大于f(100);

其实上面的可以用这个函数在0~100之间单调递增来解释,比较清楚

剩下的就是二分来找解,看一下代码还是挺容易理解的

 #include<bits/stdc++.h>
using namespace std;
double f(double x)
{
return (*x*x*x*x+*x*x*x+*x*x+*x+);
}
int main()
{ int t;
while(~scanf("%d",&t))
{
while(t--)
{
double y;
scanf("%lf",&y);
if(f()>y||f()<y)
{
printf("No solution!\n");
continue;
}
double l,r;
l=0.0;r=100.0;
double mid=50.0;
while(fabs(f(mid)-y)>1e-)
{
if(f(mid)>y)
{
r=mid;
mid=(l+r)/2.0; }
else
{
l=mid;
mid=(l+r)/2.0;
} }
printf("%.4lf\n",mid);
}
}
return ;
}

最新文章

  1. 关于Oracle表连接
  2. 理解PagerAdapter的instantiateItem()方法
  3. SQLite剖析之编程接口详解
  4. [综]前景检测GMM
  5. [转] 多进程下数据库环境的恢复:DB_REGISTER
  6. WIX 安装部署教程(六) 为你收集的七个知识点
  7. 大叔最新课程~EF核心技术剖析
  8. PowerDesigner增强
  9. 今天发现新大陆:haml和Emmet
  10. Android wifi状态三种广播
  11. AAM(Active Appearance Model)算法介绍
  12. mysql服务端安装的系列问题处理
  13. 从内存溢出看Java 环境中的内存结构(转)
  14. IOS 程序运行过程
  15. 分页插件Jpages的使用
  16. geotools实现多边形的合并&amp;缓冲区
  17. LaTeX 中图片格式错误情况
  18. solr之环境配置四
  19. How do I remove a particular element from an array in JavaScript?
  20. 直接添加viewController中的view时的注意事项

热门文章

  1. Kali-linux安装并配置NVIDIA显卡驱动
  2. eclipse 设置字体大小
  3. sharePoint中简单的父页面跳转子页面代码!
  4. HTML5视频播放插件 video.js介绍
  5. 随机数使用不当引发的生产bug
  6. http://imgbase64.duoshitong.com/ 图片转换 base64
  7. Struts2+hibernate 结合,实现登陆校验
  8. js中数组的api整理
  9. activemq整合springboot使用(个人微信小程序用)
  10. SQL优化例子