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
  1.  
2 100 -4
  1.  
 

 

Sample Output
  1.  
1.6152 No solution!
  1.  
 

 

Author
Redow
 

 

Recommend
lcy


【题意】

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


【分析】

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

注意精度!


【代码】

 

  1. #include<cstdio>
  2. #include<cmath>
  3. #include<algorithm>
  4. #include<iostream>
  5. #define debug(x) cerr<<#x<<" "<<x<<'\n';
  6. using namespace std;
  7. inline int read(){
  8. int x=0,f=1;char ch=getchar();
  9. while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  10. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  11. return x*f;
  12. }
  13. const int N=1e5+5;
  14. int n;double Y;
  15. inline double f(double x){
  16. return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
  17. }
  18. int main(){
  19. for(n=read();n--;){
  20. scanf("%lf",&Y);
  21. if(Y<f(0)||Y>f(100)){puts("No solution!");continue;}
  22. double l=0,r=100,mid,ans;
  23. while(r-l>1e-6){
  24. mid=(l+r)/2.0;
  25. if(Y-f(mid)<=1e-5){
  26. ans=mid;
  27. r=mid;
  28. }
  29. else{
  30. l=mid;
  31. }
  32. }
  33. printf("%.4lf\n",ans);
  34. }
  35. return 0;
  36. }

 

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. 前端页面——Cookie与Session有什么差别

    我们在实际生活中总会遇到这种事情,我们一旦登录(首次输入username和password)某个站点之后,当我们再次訪问的时候(仅仅要不关闭浏览器),无需再次登录.而当我们在这个站点浏览一段时间后,它 ...

  2. How to use base class's assignment operator in C++

    看了android下的代码,好长时间没看了,有个关于C++的知识点不是很清楚,查了下: 如何使用基类中的赋值运算符? 引述自http://stackoverflow.com/questions/122 ...

  3. wordpress主题升级之后返回到原来版本主题的方法

    wordpress后台经常可以看到主题提示升级,但是发现升级之后样式,颜色等都变了,不是以前的样子了,这时候如果想要返回到以前版本,前提,必须以前版本有备份. 在wordpress里面找到主题===添 ...

  4. Ubuntu中的“资源管理器”System Monitor

    我们在Windows中经常要查看“资源管理器”来了解系统运行情况,对进程进行操作等等... 在Windows桌面任务栏右键“启动任务管理器”: 学习Linux,自然也希望有类似的“资源管理器”,安装完 ...

  5. webApi2 结合uploadify 上传报错解决办法

    报错代码: Error reading MIME multipart body part. 处理办法: <httpRuntime targetFramework=" />

  6. jquery.form 和MVC4做无刷新上传DEMO

    jquery.form 和MVC4做无刷新上传DEMO HTML: <script src="~/Scripts/jquery-1.10.2.min.js"></ ...

  7. tomcat 重启报错unregister mbean error javax.management.InstanceNotFoundException

    JAVA_OPTS='-Ddruid.registerToSysProperty=true' 多个应用部署到tomcat下需要在/bin/catalina.sh下添加上面这句话 添加位置在‘cygwi ...

  8. NetBpm 数据库(9)

    原文:http://blog.csdn.net/adicovofer/article/details/1718592 关注NetBpm也很久了,可是一直没有静下心来研究,为了生活的琐事,太过浮躁……今 ...

  9. Git Step by Step – (8) Git的merge和rebase

    前面一篇文章中提到了"git pull"等价于"git fetch"加上"git merge",然后还提到了pull命令支持rebase模式 ...

  10. iOS NSURLSession VS NSURLConnection

    NSURLSession VS NSURLConnection NSURLSession可以看做是NSURLConnection的进化版,其对NSURLConnection的改进点有: * 根据每个S ...