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 <stdio.h>
#include <string>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
double cmp(double low,double high,double y);
double mcp(double x);
int main()
{
int T;
double n,m;
while(cin>>T){
while(T--){
cin>>n;
if(n<mcp(0)||n>mcp(100))
cout<<"No solution!"<<endl;
else {
m=cmp(0,100,n);
cout<<setiosflags(ios::fixed)<<setprecision(4)<<m<<endl;}
}
}
return 0;
}
double cmp(double low,double high,double y)
{
double mid;
while(high-low>1e-10){
mid=(low+high)/2.0;
if(mcp(mid)>y) high=mid;
else low=mid;
}
return mid;
}
double mcp(double x){
return 8.0*x*x*x*x+7.0*x*x*x+2.0*x*x+3.0*x+6.0;
}

递归法代码:

如果递归的判断终止条件为low<high,时间超限;因为这个类型是double型,有些数会递归很多次以至n次才会的到结果,以至超时;由于提上要求是4位小数,所以只需要让low<high-0.0000001即可;

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
double cmp(double low,double high,double y);
double mcp(double x);
int main()
{
int T;
double n,m;
while(cin>>T){
while(T--){
cin>>n;
if(n<mcp(0)||n>mcp(100))
cout<<"No solution!"<<endl;
else {
m=cmp(0,100,n);
cout<<setiosflags(ios::fixed)<<setprecision(4)<<m<<endl;}
}
}
return 0;
}
double cmp(double low,double high,double y)
{
double mid=(low+high)/2;
if(high-low>1e-10){
if(mcp(mid)>y)
return cmp(low,mid,y);
else if(mcp(mid)<y)
return cmp(mid,high,y);
else return mid;
}
return mid;
}
double mcp(double x){
return 8.0*x*x*x*x+7.0*x*x*x+2.0*x*x+3.0*x+6.0;
}

思路:先要判断这个函数的单调性,之后在就容易多了,给你一个数y;求解出对应的x,如果x是在0-100之间输出x浮点数为4;否则输出“No solution!”;

说白了就是把y移到等式左边是f(x)= 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 -Y;求是零点的值;如果x是在0-100之间输出x,浮点数为4;否则输出“No solution!”;

hdu 2199的更多相关文章

  1. HDU 2199 Can you solve this equation?(二分精度)

    HDU 2199 Can you solve this equation?     Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == ...

  2. hdu 2199 (二分)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/1000 ...

  3. hdu 2199 Can you solve this equation?(高精度二分)

    http://acm.hdu.edu.cn/howproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/1000 MS ...

  4. (二分搜索)Can you solve this equation? -- hdu -- 2199

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=2199 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  5. HDU 2199 Can you solve this equation?(二分解方程)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/10 ...

  6. ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分

    Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...

  7. hdu 2199 Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  8. hdu 2199 Can you solve this equation?

    #include<stdio.h> #include<math.h> double f(double x) { return 8*x*x*x*x+7*x*x*x+2*x*x+3 ...

  9. hdu 2199:Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  10. HDU 2199 Can you solve this equation? (二分 水题)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

随机推荐

  1. mysql/tokudb安装

    一.环境要求:    Operating Systems:64-bit Linux     Memory: >=1G 二.安装步骤 1.下载安装包mysql-5.5.41-tokudb-7.5. ...

  2. jQuery自学笔记(三):jQuery动画效果

    jQuery隐藏和显示: 使用 hide( ) 和 show( ) 方法来隐藏和显示 HTML 元素: 语法: $(selector).hide(speed,callback); $(selector ...

  3. ajax初学

    //参数说明url:请求文件地址//fnSucc:请求成功执行的函数,请求成功的条件为readyState状态码为4:且status状态码为200,status状态为浏览器请求返回的状态码//在fnS ...

  4. Html5 学习之 Html5功能判断插件 Modernizr

    ---恢复内容开始--- Modernizr 浏览器对HTML5和CSS3开发的功能检测类库 由于当前用户使用的浏览器版本较多,对H5和CSS3的支持也各不相同.前端的开发者,在使用一些新的特性的时候 ...

  5. 三星手机照相机出现了故障,htc无法连接无线网

    1 重启 2 若还不行,把内存卡,电池拿掉, 也可下载一个相机应用

  6. HTML&CSS基础学习笔记1.17-表格的头部与尾部

    表格的头部和尾部 既然有标签表示表格的主体,那么自然表格的头部和尾部也有对应的标签. HTML中使用<thead>标签表示表格的头部,使用<tfoot>标签表示表格的尾部. 有 ...

  7. C语言初学 转义字符举例

    #include<stdio.h> main() { printf("\101 \x42 C\n"); printf("I say:\"How ar ...

  8. 记录终端输出的LOG到文件

    先要说明为什么要记录终端会话,因为常会遇到这样的情况,终端是有缓存大小限制的,当在终端打印的消息超出缓存范围,它前面的打印消息就自动丢失了,这对于我们调试程序会造成障碍,所以有记录完整终端打印消息的必 ...

  9. Feedly订阅Blog部落格RSS网摘 - Blog透视镜

    网络信息爆炸的时代,如何更有效率地阅读文章,订阅RSS网摘,可以快速地浏览文章标题,当对某些文章有兴趣时,才点下连结连到原网站,阅读更详细的文章,Feedly Reader阅读器除了提供在线版订阅RS ...

  10. Altium Designer (protel) 各版本“故障”随谈

    Altium 的版本很多,每个版本都或多或少有些可容忍或可不容忍的问题,此贴只是希望各位能将遇到的问题写出来,只是希望 给还在使用 altium 的网友一些参考,也希望有些能被 altium 所接受@ ...