Can you solve this equation?

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

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   |   We have carefully selected several similar problems for you:  2899 2289 2298 3400 1969 

 
  二分搜索
  先要判断方程的单调性。可用 cal()<=y && y<=cal() 判断。
  二分法不断提高精度,最后到某个精度位置输出就是正确答案。
  注意题目给出的第一组测试数据是错的,AC代码出来的结果是1.6151,而不是1.6152。
  代码:
 #include <iostream>
#include <cmath>
#include <iomanip>
using namespace std; double cal(double x)
{
return *pow(x,) + *pow(x,) + *pow(x,) + *x + ;
}
double GetAns(double y)
{
double a=,b=;
while(b-a>1e-){
double mid=(a+b)/;
cal(mid)<y?a=mid:b=mid;
}
return (a+b)/;
}
int main()
{
int T;
cin>>T;
while(T--){
double y;
cin>>y;
if(cal()<=y && y<=cal()){
cout<<setiosflags(ios::fixed)<<setprecision();
cout<<GetAns(y)<<endl;
}
else
cout<<"No solution!"<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 2199:Can you solve this equation?(二分搜索)的更多相关文章

  1. hdu 2199 Can you solve this equation?(二分搜索)

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

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

  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?(二分解方程)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/10 ...

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

  6. HDU 2199 Can you solve this equation? (二分 水题)

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

  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. js中对象概念的声明

  2. MongoDB之bson的介绍

    MongoDB之bson的介绍 1. 什么是bson BSON是一种类json的一种二进制形式的存储格式,简称Binary JSON,它和JSON一样,支持内嵌的文档对象和数组对象,但是BSON有JS ...

  3. 关于Java单例

    参考资料:http://blog.csdn.net/haoel/article/details/4028232 public class SingletonTest implements Runnab ...

  4. Unity Shader Billboard

    记录来源于ShaderLab开发实战详解 Shader "Tut/Project/Billboard_1" { Properties { _MainTex ("Base ...

  5. Jquery 鼠标事件解析

    1 mouseover与mousemove的区别: mouseover是当鼠标移动到对象时产生,只产生一次,这时如果继续在对象上移动,不会再产生mouseover事件,而是mousemove事件,mo ...

  6. Homebrew安装

    1. 安装Command Line Tools 终端输入 xcode-select --install 回车,若下载慢,可搜索Command line Tools的pkg文件,自行安装. 或者直接安装 ...

  7. JS设置cookie,删除cookie

    js设置cookie有很多种方法. 第一种:(这个是w3c官网的代码) <script> //设置cookie function setCookie(cname, cvalue, exda ...

  8. linux挂载硬盘失败,报错!

    剛把我的一顆硬碟 ( NTFS ) 接到 Ubuntu 桌機上. 然後要 mount  的時候,出現了下面的訊息: DBus error org.gtk.Private.RemoteVolumeMon ...

  9. [整理]Ajax Post请求下的Form Data和Request Payload

    Ajax Post请求下的Form Data和Request Payload 通常情况下,我们通过Post提交表单,以键值对的形式存储在请求体中.此时的reqeuest headers会有Conten ...

  10. matlab之waitbar() delete() close()

    matlab之waitbar() delete() close() 三者之间的关系: 在显示某个程序的进度时,用waitbar函数显示进度条,当程序进行完毕时,用close 或 delete函数关闭此 ...