HDUOJ---Can you solve this equation?
Can you solve this equation?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5667 Accepted Submission(s): 2681 http://acm.hdu.edu.cn/showproblem.php?pid=2199
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
二分搜索
代码:
#include<iostream>
#include<cstdio>
#define sum(x) ((8*x*x*x*x)+(7*x*x*x)+(2*x*x)+(3*x)+(6))
using namespace std;
int main()
{
int t;
double y,mid,left,right;
cin>>t;
while(t--)
{
scanf("%lf",&y);
left=0.0,right=100.0;
if(y>=6.0&&y<=sum(100))
{
while(right-left>1e-8)
{
mid=(left+right)/2.0;
if(sum(mid)-y>1e-8)
right=mid;
else
if(y-sum(mid)>1e-8)
left=mid;
else
break;
}
printf("%.4lfn",mid);
}
else
puts("No solution!");
}
return 0;
}
- 优化算法——差分进化算法(DE)
- 通过shell脚本批量验证dataguard的有效性(r7笔记第96天)
- JavaWeb17-案例之ajax(Java真正的全栈开发)
- JavaWeb15-DBUtils(Java真正的全栈开发)
- 利用Theano理解深度学习——Multilayer Perceptron
- JavaWeb14-事务,连接池(Java正在的全栈开发)
- 利用Theano理解深度学习——Logistic Regression
- JavaWeb13-设计模式案例实现(Java真正的全栈开发)
- 运维平台的建设思考-元数据管理(三)(r8笔记第15天)
- JavaWeb12-JSP, EL表达式,JSTL标签
- JavaWeb11-jsp.cookie.session(1)
- 交互式使用 R题(shell)
- union(并),setdiff(差),intersect(交)R语言含义
- JavaWeb11-jsp.cookie.session(2)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 记一次关于MySQL与PHP的蠢事
- 编写一个简单的JQuery插件
- Spring AOP异常:Error creating bean with name ‘org.springframework.aop.aspectj.
- Tomcat7 Redis Session 共享
- CodeIgniter (CI) 框架学习 -- load_class
- Laravel框架学习 -- php artisan down/up
- Spring中基于注解@AspectJ的AOP实现
- python提高--running-python-code-contained-in-a-strin
- linux shell 监控脚本 及 邮件发送
- Laravel框架学习 -- 安装
- Redis 键管理与小功能
- redis 数据持久化
- 不蒜子 | 给网站、博客文章添加阅读次数统计,我用两行代码 搞定计数
- redis 主从复制
- Spring 当一个接口多个实现时,怎么注入