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. javascript对数据处理

    数组去重 法一: // 遍历数组,建立新数组,利用indexOf判断是否存在于新数组中,不存在则push到新数组,最后返回新数组 function unique(ar) { var ret = []; ...

  2. Centos yum安装java jdk1.8

    yum -y install java-1.8.0-openjdk* 安装后 java -version查看版本 检验是否安装成功. 其安装位置 /usr/lib/jvm/java-1.8.0-ope ...

  3. hive cst 时间转换

    select from_unixtime(unix_timestamp(r.collecttime,'EEE MMM dd HH:mm:ss zzz yyyy'),'yyyy-MM-dd HH:mm: ...

  4. DWZ主从表界面唯一性验证(自写js)(一)

    最近在项目中遇到一个问题,它的需求是: 利用DWZ的主从表结构批量添加课程信息,需要在触发课程代码文本框的离开事件时验证: 1.是否选择学院. 2.数据库里是否已存在该课程代码. 3.多条数据添加时, ...

  5. 在C++中实现不可继承的类

    逛下bbs,“在C++中实现不可继承的类”,瞒有意思的. class NoInherite { friend class Seal; private: NoInherite(void) {} ~NoI ...

  6. Unity3D热更新LuaFramework入门实战

    http://blog.sina.com.cn/s/blog_6788cd880102w8qy.html http://www.manew.com/thread-91845-1-1.html http ...

  7. ubuntu下安装程序的五种方法

    在ubuntu当中,安装应用程序我所知道的有三种方法,分别是apt-get,dpkg安装deb和make install安装源码包三种.下面针对每一种方法各举例来说明. 一.apt-get方法 使用a ...

  8. linux环境中,ssh登录报错,Permission denied, please try again.

    问题描述: 今天早上一个同事反应一个问题,通过ssh登录一台测试机的时候,发现两个账号,都是普通账号,一个账号能够登录, 另外一个账号无法登录.问他之前有做过什么变更吗,提到的就是之前有升级过open ...

  9. [web] spring boot 整合MyBatis

    1.maven依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...

  10. SQLServer2008/2005 生成数据字典语句

    SELECT 表名 then d.name else '' end, 表说明 then isnull(f.value,'') else '' end, 字段序号=a.colorder, 字段名=a.n ...