HDU 2199 Can you solve this equation?
2015-07-30 18:21
405 查看
Can you solve this equation?
[align=left]Problem Description[/align]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.
[align=left]Input[/align]
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);
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
2
100
-4
[align=left]Sample Output[/align]
1.6152
No solution!
#include<cstdio> #include<algorithm> #include<cmath> using namespace std; double cal(double x) { return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6; } int main() { double x,l,r; int t; scanf("%d",&t); while(t--) { scanf("%lf",&x); if(x<cal(0)||x>cal(100)) { printf("No solution!\n"); continue; } l=0,r=100; while(fabs(l-r)>1e-8) { double mid=(l+r)/2; if(cal(mid)>x) r=mid; else l=mid; } printf("%.4lf\n",l); } return 0; }
相关文章推荐
- JTable合并表头
- 线程池和数据库连接池的原理
- vim 7.4 插件安装管理
- Java编程思想:第3章 操作符
- Redis同步操作失败的原因
- Drupal 菜单系统 hook_menu
- 严重: Skipped installing application listeners due to previous error(s)
- LeetCode_199 Binary Tree Right Side View
- socket网络编程
- c point
- javascript实现列表滚动的方法
- Linux操作系统下的死循环程序响应
- Redis数据类型之字符串
- 一些关于linux的一些简单的应用
- Scala访问权限修饰符:private和private[this]
- Oracle TYPE OBJECT详解
- 使用G++编译运行c++(by命令行)
- spring - ioc和aop
- HDU 4972 Bisharp and Charizard 想法题
- Jquery常用的的选择器及容易忽视的小错误