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. Mysql 索引问题集锦

    一.Mysql 中的索引 索引:顾名思义用来检索.查找数据的key (字段) 几种Mysql 中的常见索引分类:普通索引(联合索引).唯一索引.主键索引.全文索引 优点:使得查询数据变快 缺点:更新数 ...

  2. pdf转eps后存在大片空白的处理

    之前pdf转eps的方式是用acrobat直接转,发现每次转完后,图片都显示在一张A4纸上,插入到论文中时会出现大片空白:但在pdf中是没有这么多空白的,与裁剪没关系. 后来在 http://tex. ...

  3. 安装使用swoole

    swoole首页:https://www.swoole.com/ 方法1:使用pecl安装 pecl install swoole 注意,php版本必须是7.0以及7.0以上的版本. 方法2:编译源码 ...

  4. myecplise ssh项目配置上遇到的问题

    版本:spring3.1+hib4.1+struts2.1 学习项目使用此版本运行时,总是会遇到各样的错误,在这里做一下记录. 问题1:log4j相关 spring的web项目,执行时报错: 信息: ...

  5. mybatis异常解决:class path resource [SqlMapConfig.xml] cannot be opened because it does not exist

    解决方法: 缺失SqlMapConfig.xml文件.

  6. php 生成订单号201807205598981

    php版 /** * 生成唯一订单号 */ public function build_order_no() { $no = date('Ymd').substr(implode(NULL, arra ...

  7. Spring 配置详解

    spring4配置文件详解 一.配置数据源 基本的加载properties配置文件 <context:property-placeholder location="classpath* ...

  8. python爬虫之scrapy文件下载

    我们在写普通脚本的时候,从一个网站拿到一个文件的下载url,然后下载,直接将数据写入文件或者保存下来,但是这个需要我们自己一点一点的写出来,而且反复利用率并不高,为了不重复造轮子,scrapy提供很流 ...

  9. LAMP 版本查看

    mysql 1 在终端下执行 mysql -V 2  mysql --help |grep Distrib 3 在mysql 里查看 select version() 4 在mysql 里查看 sta ...

  10. SSM框架整合系列——第一步

    环境: JDK8 idea2018.2 maven3.5 spring和springMVC是天然集成,所以只需要解决mybatis和spring的整合问题,重点整合mybatis和spring的两个东 ...