HDOJ 2199 HDU 2199 Can you solve this equation? ACM 2199 IN HDU
题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=2199
题目描述:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 322 Accepted Submission(s): 148
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!
题目分析:
通常的递归方法吗很遗憾 , RE了............. 没办法, 只能循环了.
下面的是递归 RE 的代码 :
std y douEql a b fabs a b cal n POW4n POW3n POWn n biSearch l r douEql lr douEql y cal l l mid l r douEql y cal mid mid cal mid y biSearch lmid biSearch mid r T scanfT T scanfy cal y cal y printf res biSearch res printf printfres
AC代码如下:
#include <iostream>
#include <cmath>
using namespace std;
#define POW(x) ( (x) * (x) )
#define POW3(x) ( POW(x) * (x) )
#define POW4(x) ( POW(x) * POW(x) )
double y = 0;
double cal ( double n )
{
return 8.0 * POW4(n) + 7 * POW3(n) + 2 * POW(n) + 3 * n + 6 ;
}
int main ()
{
int T;
scanf ( "%d",&T );
while ( T -- )
{
scanf ( "%lf",&y );
if ( cal(0) > y || cal(100) < y )
{
printf ( "No solution!\n" );
continue;
}
double l = 0.0, r = 100.0,res = 0.0;
while ( r - l > 1e-6 )
{
double mid = ( l + r ) / 2.0;
res = cal ( mid );
if ( res > y )
r = mid - 1e-6;
else
l = mid + 1e-6;
}
printf ( "%.4lf\n",( l + r ) / 2.0 );
}
return 0;
}
转载于:https://www.cnblogs.com/MiYu/archive/2010/08/18/1802686.html
HDOJ 2199 HDU 2199 Can you solve this equation? ACM 2199 IN HDU相关推荐
- HDOJ 1157 HDU 1157 Who's in the Middle ACM 1157 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1157 题目描述: ...
- HDOJ HDU 2080 夹角有多大II ACM 2080 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=2080 ...
- HDU 2199 Can you solve this equation?【二分查找】
解题思路:给出一个方程 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,求方程的解. 首先判断方程是否有解,因为该函数在实数范围内是连续的,所以只需使y的值满足f(0)< ...
- hdu 2199 Can you solve this equation? 二分
1.精度问题 由于是double类型,r=mid 而不是r=mid-1 2.如果首位两端(f(0)和f(100))同号,证明解不在[1,100]区间内 这是我之所以TE的原因,没有预先判断 3.若在这 ...
- hdoj 2199 Can you solve this equation? 【二分枚举】
题意:给出一个数让你求出等于这个数的x 策略:如题.因为整个式子是单调递增的,所以可以用二分. 要注意到精度. 代码: #include <stdio.h> #include <st ...
- HDOJ 1874 HDU 1874 畅通工程续 ACM 1874 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1874 ...
- HDOJ 1213 HDU 1213 How Many Tables ACM 1213 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1213 ...
- HDU 1086 You can Solve a Geometry Problem too
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...
- HDOJ 1016 HDU 1016 Prime Ring Problem ACM 1016 IN HDU
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1016 题目描述: Prime Ring Problem Time Limit: 4000/2000 ...
最新文章
- Kataspace:用HTML5和WebGL创建基于浏览器的虚拟世界
- 会用python把linux命令写一遍的人,进大厂有多容易?
- Google Chrome插件导出与安装
- 统计子串出现次数 STL map
- 最长回文子串 hihocode 1032 hdu 3068
- 2015年奇虎360服务器开发C++电话面试问题
- 16_Android生命周期再介绍,通过androidconfigChanges属性让界面旋转时不改变状态中保留的值
- JQuery $作用
- Hello JavaFX 2.0:命令行介绍
- 插入文件找不到桌面了?
- layui 单选项 点击显示与隐藏 很实用
- wpf之通过MVVM绑定MouseEnter
- html中input type什么意思,HTML中type是什么意思
- html+css简单的实现360搜索引擎首页面
- java catch 空指针异常_在Java中避免空指针异常(Null Pointer Exception)
- Cisco Packet Tracer 配置交换机与路由器静态路由
- 使用信用卡 要避开这些陷阱
- 一种用于NDN的安全的链路状态路由协议
- 订单中心项目分析与总结
- 人工智能python编程面试题_5000字纯干货|人工智能笔试题目及答案