MiYu原创, 转帖请注明 : 转载自 ______________白白の屋

题目地址:
         http://acm.hdu.edu.cn/showproblem.php?pid=2199
题目描述:

Can you solve this equation?

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!

题目分析:

很明显,这是一个2分搜索的题目, 但是注意下题目的数据!! 1e10 的实数!! 而且精度是要求在 0.0001 . 所以就算是2分数据量依旧比较大,如果用
通常的递归方法吗很遗憾 , 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代码如下:

MiYu原创, 转帖请注明 : 转载自 ______________白白の屋

#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相关推荐

  1. HDOJ 1157 HDU 1157 Who's in the Middle ACM 1157 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋   题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1157 题目描述: ...

  2. HDOJ HDU 2080 夹角有多大II ACM 2080 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=2080 ...

  3. HDU 2199 Can you solve this equation?【二分查找】

    解题思路:给出一个方程 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,求方程的解. 首先判断方程是否有解,因为该函数在实数范围内是连续的,所以只需使y的值满足f(0)< ...

  4. hdu 2199 Can you solve this equation? 二分

    1.精度问题 由于是double类型,r=mid 而不是r=mid-1 2.如果首位两端(f(0)和f(100))同号,证明解不在[1,100]区间内 这是我之所以TE的原因,没有预先判断 3.若在这 ...

  5. hdoj 2199 Can you solve this equation? 【二分枚举】

    题意:给出一个数让你求出等于这个数的x 策略:如题.因为整个式子是单调递增的,所以可以用二分. 要注意到精度. 代码: #include <stdio.h> #include <st ...

  6. HDOJ 1874 HDU 1874 畅通工程续 ACM 1874 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=1874 ...

  7. HDOJ 1213 HDU 1213 How Many Tables ACM 1213 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=1213 ...

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

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

最新文章

  1. Kataspace:用HTML5和WebGL创建基于浏览器的虚拟世界
  2. 会用python把linux命令写一遍的人,进大厂有多容易?
  3. Google Chrome插件导出与安装
  4. 统计子串出现次数 STL map
  5. 最长回文子串 hihocode 1032 hdu 3068
  6. 2015年奇虎360服务器开发C++电话面试问题
  7. 16_Android生命周期再介绍,通过androidconfigChanges属性让界面旋转时不改变状态中保留的值
  8. JQuery $作用
  9. Hello JavaFX 2.0:命令行介绍
  10. 插入文件找不到桌面了?
  11. layui 单选项 点击显示与隐藏 很实用
  12. wpf之通过MVVM绑定MouseEnter
  13. html中input type什么意思,HTML中type是什么意思
  14. html+css简单的实现360搜索引擎首页面
  15. java catch 空指针异常_在Java中避免空指针异常(Null Pointer Exception)
  16. Cisco Packet Tracer 配置交换机与路由器静态路由
  17. 使用信用卡 要避开这些陷阱
  18. 一种用于NDN的安全的链路状态路由协议
  19. 订单中心项目分析与总结
  20. 人工智能python编程面试题_5000字纯干货|人工智能笔试题目及答案

热门文章

  1. 疑惑?人工智能兴起为什么带火了Python,看完这篇你就明白了
  2. 计算机视觉论文-2021-07-09
  3. 收藏 | 可能是最详尽的PyTorch动态图解析
  4. 前沿 | 张钹院士畅谈清华大学如何办人工智能专业
  5. python魔法方法(一)
  6. 用 LSTM 做时间序列预测的一个小例子
  7. Matlab解析LQR与MPC的关系
  8. 2014秋应用计算机,2014年秋计算机应用基础》期末试卷A(A3版).doc
  9. 为什么要 conda 作用_武汉精神堡垒有什么作用 为什么要做?
  10. Spring Data JPA 写SQL语句也可以如此简单