Can you solve this equation?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 27728    Accepted Submission(s): 11717

 

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!
 
 

 

Author
Redow
 

 

Recommend
lcy


【题意】

在[0,100]内找一个方程的实数解。


【分析】

求导易得函数单增,只需二分即可。

注意精度!


【代码】

 

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int N=1e5+5;
int n;double Y;
inline double f(double x){
return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
} int main(){
for(n=read();n--;){
scanf("%lf",&Y);
if(Y<f(0)||Y>f(100)){puts("No solution!");continue;}
double l=0,r=100,mid,ans;
while(r-l>1e-6){
mid=(l+r)/2.0;
if(Y-f(mid)<=1e-5){
ans=mid;
r=mid;
}
else{
l=mid;
}
}
printf("%.4lf\n",ans);
}
return 0;
}

 

HDU 2199 Can you solve this equation(二分答案)的更多相关文章

  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 Can you solve this equation? (二分 水题)

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

  3. HDU - 2199 Can you solve this equation? 二分 简单题

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

  4. hdu 2199 Can you solve this equation? 二分

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

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

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

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

  8. HDU 2199 Can you solve this equation?【二分查找】

    解题思路:给出一个方程 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,求方程的解. 首先判断方程是否有解,因为该函数在实数范围内是连续的,所以只需使y的值满足f(0)< ...

  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. SSL 证书服务推荐

    最近要用到ssl.故做了一些搜索 1.Let's Encrypt:免费,快捷,支持多域名(不是通配符),三条命令即时签署+导出证书.缺点是暂时只有三个月有效期,到期需续签. 2.StartSSL免费D ...

  2. SharePoint 2013 隐藏左边快速启动菜单栏(Hiding the Quick Launch Bar)

    在SharePoint 2013默认网站页面中,很多时候,我们需要隐藏左边快速启动菜单栏,这时我们可以通过下面的样式来实现隐藏它. 和SharePoint 2010不太一样,方法改了,不过性质是一样的 ...

  3. Base64编码——学习笔记

    Base64是一种编码方式. 非加密 chcp->936 编码流程: 位数不够后面补0,例中补了2个0. 末尾加=表示结束符. GB2312,有些敏感词不能显示. GBK,是GB2312升级版. ...

  4. 错误 Unable to find vcvarsall.bat 的终极无敌最完美的解决办法

    Windows 上通过 pip 安装 python 包,经常会出现这种错误. 如:pip install pyodbc. 这种错误的简单明了解释就是:python 编译器找不到计算机上面的 VC 编译 ...

  5. 【scala】 scala 类 (五)

    1.scala类 1.class 关键字 2.var 属性 默认生成getter/setter 方法 3.val 属性 默认生成getter 方法 4. 自定义getter /setter 方法 , ...

  6. Go之单元测试

    go单元测试需要按照gotest的规范来编写: 1.文件名必须以xx_test.go命名 2.方法必须是Test[^a-z]开头 3.方法参数必须 t *testing.T   在运行gotest的时 ...

  7. iOS 定时器的比较

    然而,在iOS中有很多方法完成以上的任务,到底有多少种方法呢?经过查阅资料,大概有三种方法:NSTimer.CADisplayLink.GCD.接下来我就一一介绍它们的用法. 一.NSTimer 1. ...

  8. python --help查询python相关命令

    C:\Users\lenovo>python --help usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ... O ...

  9. 【RF库Collections测试】Keep In Dictionary

    Name:Keep In DictionarySource:Collections <test library>Arguments:[ dictionary | *keys ]Keeps ...

  10. Selenium 延时等待

    在 Selenium 中, get() 方法会在网页框架加载结束后结束执行,此时如果获取 page_source ,可能并不是浏览器完全加载完成的页面: 如果某些页面有额外的 Ajax 请求,我们在网 ...