Hdoj 2199.Can you solve this equation? 题解
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? 题解的更多相关文章
- hdoj 2199 Can you solve this equation?【浮点型数据二分】
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdoj 2199 Can you solve this equation? 【二分枚举】
题意:给出一个数让你求出等于这个数的x 策略:如题. 由于整个式子是单调递增的.所以能够用二分. 要注意到精度. 代码: #include <stdio.h> #include <s ...
- 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 ...
- 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 == ...
- 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 ...
- 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 ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 2199:Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 2199 Can you solve this equation? (二分 水题)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- Individual Project "写一个能自动生成小学四则运算题目的程序"
一.题目简介 写一个能自动生成小学四则运算题目的程序. 初步拟定要实现的功能后,估计一下自己需要花多长时间.编程过程中记录自己实际用了多长时间. 然后和同学们比较一下各自程序的功能.实现方法的异同等等 ...
- git repository description
Git - Plumbing and Porcelainhttps://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain gith ...
- mysql 5.7:show_compatibility_56
show_compatibility_56 - rudy gao - CSDN博客 https://blog.csdn.net/rudygao/article/details/50403107 [SO ...
- php获取URL扩展名
一切拿代码来说话: 举例:'http://www.sina.com.cn/abc/de/fg.php?id=1': $url = 'http://www.sina.com.cn/abc/de/fg.p ...
- linux关闭触摸板
关闭触摸板 sudo modprobe -r psmouse 如果打开触摸板就是: sudo modprobe psmouse
- K3 WISE安全认证方式
k/3中间层注册三种安全认证方式: 交互式用户方式,网络服务方式,信任方式,是指组件服务中生成的COM+应用程序中的组件包的运行账户(注册中间层后产生很多ebo开头的和kdsvrmgr组件包). 三种 ...
- Spring 基于XML配置
基于XML的配置 对于基于XML的配置,Spring 1.0的配置文件采用DTD格式,Spring2.0以后采用Schema格式,后者让不同类型的配罝拥有了自己的命名空间,使得配置文件更具扩展性.此外 ...
- 你不知道的JavaScript——第一章:作用域是什么?
编译原理 JavaScript事实上是一门编译语言,但与传统的编译语言不同,它不是提前编译的,编译结果也不能在分布式系统中进行移植. 任何JavaScript代码片段在执行前都要进行编译(通常就在执行 ...
- java中级——集合框架【1】-ArrayList
集合框架----ArrayList 引子:我们先来看看传统数组的用法 写一个Hero对象类 package cn.jse.t1; public class Hero { public String n ...
- 运维常用mysql语句
1..select @@version; ##查询当前mysql的版本. 2. show variables like 'port';##查看mysql实例的端口. 3.show variables ...