Problem Description

Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 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!

Author

Redow


思路

这个问题可以用二分法解决,因为给定的函数是单调的,所以可以根据要求的精度不断二分找答案

详见代码

代码

#include<bits/stdc++.h>
using namespace std; double f(double x)
{
return 8*x*x*x*x + 7*x*x*x + 2*x*x + 3*x + 6 ;
} int main()
{
int n;
cin >> n;
while(n--)
{
double t;
cin >> t;
double l = 0, r = 100.0;
if(t<f(0) || t>f(100.0))
{
cout << "No solution!\n";
continue;
}//因为函数单调,所以可以这么判断
double mid;
while(r-l>1e-8)
{
mid = (l+r)/2;
double ans = f(mid);
if(ans>t)
r = mid;
if(ans<t)
l = mid;
}
printf("%.4lf\n",l);
}
return 0;
}

Hdoj 2199.Can you solve this equation? 题解的更多相关文章

  1. hdoj 2199 Can you solve this equation?【浮点型数据二分】

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

  2. hdoj 2199 Can you solve this equation? 【二分枚举】

    题意:给出一个数让你求出等于这个数的x 策略:如题. 由于整个式子是单调递增的.所以能够用二分. 要注意到精度. 代码: #include <stdio.h> #include <s ...

  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. 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 == ...

  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?(二分搜索)

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

  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 ( ...

随机推荐

  1. Django之Django终端打印SQL语句

    Django之Django终端打印SQL语句 在Django项目中,settings.py文件中,在最后添加如下代码即可实现在Django终端打印SQL语句. LOGGING = { 'version ...

  2. nginx配置ssl证书后无法访问https

    一直听说https更安全,要安装证书,一直没试过,今天终于试了试 首先得有个http的域名网站,服务器. 到阿里云的安全-ssl证书管理申请一个免费的,可以绑定一个域名  然后完善资料,照着例子配置一 ...

  3. CLOUD流程设置

    流程-反写规则 允许超额

  4. 建议3---理解Python与C语言的不同之处

    我们都知道,Python的底层是用C语言实现的,但切忌用C语言的思维和风格来编写Python代码.Python与其他语言有很多不同,以下来进行简单的分析: (1)"缩进"与“{}” ...

  5. linux audit (9)--生成audit报表

    aureport这个命令可以生成一个总结性的柱状图报表,默认情况下,在/var/log/audit目录下的所有日志文件都会生成一个报表,也可以使用如下命令来指定一个不同的文件,aureport opt ...

  6. 使用getopts处理输入参数

    在编写shell脚本中,需要输入参数,使用过程中,getopts更加方便.可以很好的处理用户输入的参数和参数值. 参加如下一段脚本: #!/bin/bash while getopts ": ...

  7. 网站滚动n个像素后,头部固定

    //固顶 $(window).scroll(function() { var top = $(window).scrollTop(); if(top>=1200){ $(".x_men ...

  8. 老男孩python学习自修第五天【集合】

    特点: (1)无序 (2)不重复 使用场景: (1)关系测试 (2)去重 x & y 求交集 x | y 求并集 x - y 求差集 x ^ y 求对称差集 x.intersection(y) ...

  9. Mybatis之collection嵌套查询mapper文件写法

    mapper.xml写法举例 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper ...

  10. TP5上传图片

    模板: <form action="{:url('Temp/addTempDo')}" enctype="multipart/form-data" met ...