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. shell中的declare命令

    declare命令有如下选项: -a 声明一个数组 -i 声明一个整型 -f 打印所有函数定义 -F 仅打印函数名字 -r 声明一个readonly变量,该变量的值无法改变,并且不能为unset -x ...

  2. 关于ROW_NUMBER函数的使用(The use of ROW_NUMBER function )

    1.用于删除重复记录(The use of to delete the common record) 例子:(Example) #1初始化数据(Initialize the data) CREATE ...

  3. JSONP的原理

    JSONP的原理 JSONP的最基本的原理是:动态添加一个<script>标签,而script标签的src属性是没有跨域的限制的. <script type="text/j ...

  4. js formatString 格式化字符串

    /* 函数:格式化字符串 参数:str:字符串模板: data:数据 调用方式:formatString("api/values/{id}/{name}",{id:101,name ...

  5. js中的逻辑或和逻辑与

    a=''||'abc';                              //返回什么?  'abc' a=1||2;                                  // ...

  6. php 之 分页查询的使用方法及其类的封装

    一.分页的使用: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  7. HTML&CSS基础学习笔记1.24-input标签的单选与多选

    单选和多选 单选框和多选框是用<input>标签来实现的. <input>标签的type属性值为"checkbox"时,表示多选框,为"radio ...

  8. 部署在腾讯云的公益网站遭受了一次CC攻击

    版权声明:本文由黄希彤  原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/651089001483090830 来源:腾云阁 ...

  9. cf B. Eight Point Sets

    http://codeforces.com/contest/334/problem/B #include <cstdio> #include <cstring> #includ ...

  10. Codeforces 219D Choosing Capital for Treeland

    http://codeforces.com/problemset/problem/219/D 题目大意: 给出一棵树,但是它的边是有向边,选择一个城市,问最少调整多少条边的方向能使一个选中城市可以到达 ...