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!
题意:利用二分法求解;
解题思路:用最简单的二分就能过,但是!!!注意精度最少1e-6;
感悟:终于知道学长说的,二分最蛋疼的就是控制精度了;
代码:
#include

#include

using namespace std;

double iteration(double x)

{  

    double
fx;

   
fx=8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;

    return
fx;

}

int main()

{

   
//freopen("in.txt", "r", stdin);

    int n;

    double
y,x1,x2,x;

   
scanf("%d",&n);

    for(int
i=0;i

    {

       
scanf("%lf",&y);

       
x1=-1;

       
x2=101;

       
if(y<6||y>807020306)

       
{

           
printf("No solution!\n");

           
continue;

       
}//最大解和最小解判断有没有解

       
else

       
{

           
while(true)

           
{

               
x=(x1+x2)/2;

               
if(x2-x1<1e-6)//这里精度最小就得是1e-6

               
{

                   
printf("%.4lf\n",x);

                   
break;

               
}

               
else

               
{

                   
if(iteration(x)==y)

                   
{

                       
printf("%.4lf\n",x);

                       
break;

                   
}

                   
else if(iteration(x)

                       
x1=x;

                   
else if(iteration(x)>y)

                       
x2=x;

              
}

           
}

       
}

    
}

    
return 0;

}

Can you solve this equation?的更多相关文章

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

  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?(高精度二分)

    http://acm.hdu.edu.cn/howproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/1000 MS ...

  5. HDU 2199 Can you solve this equation? (二分 水题)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  6. hdoj 2199 Can you solve this equation?【浮点型数据二分】

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  7. Can you solve this equation?(二分)

    Can you solve this equation? Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Ja ...

  8. Can you solve this equation?

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...

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

  10. 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. [Troubleshooting] Inter VT 主板已开启,但测试工具显示未开启.

    一周前给神船Z7SL3重装了Win10的系统,但安装VMware时遇到了比较诡异的事 主板确定开启了VT  但是VMware显示不支持64位 用工具Securable和Intel(R) Process ...

  2. PuTsangTo-单撸游戏开发01 Flag与计划

    先立下flag,至少1年之内坚持并2年之内完成自己的一个梦想--游戏开发. 没有参加培训也不打算参加培训,就纯靠业余时间自学并用自己的思路完成一整套游戏体系.做出此决心时也已经做好准备烂尾了,但是有种 ...

  3. python之gui-tkinter可视化编辑界面 自动生成代码

    首先提供资源链接 http://pan.baidu.com/s/1kVLOrIn#list/path=%2F

  4. Spark组件

    1,Application application(应用)其实就是用spark-submit提交的程序.比方说spark examples中的计算pi的SparkPi.一个application通常包 ...

  5. Linux入门之常用命令(7)压缩

    compress filename 压缩   -d解压缩  *.Z bzip -d解压缩 -z压缩 *.bz2 bzcat filename .bz2 读取压缩文件内容 gzip -d解压缩  -#压 ...

  6. 决策树模型组合之随机森林与GBDT

    版权声明: 本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com, 本文可以被全部的转载或者部分使用,但请注明出处,如果有问题,请联系wheeleast@gm ...

  7. webservice部署到服务器报错

    System.Net.WebException: 基础连接已经关闭: 发送时发生错误. ---> System.IO.IOException: 从传输流收到意外的 EOF 或 0 个字节. 在 ...

  8. Ubuntu16.04下安装redis

    Ubuntu16.04下安装redis 保证网络畅通,选定好下载工作路径,执行以下命令下载redis-3.2.6: sudo wget http://download.redis.io/release ...

  9. ZOJ2185 简单分块 找规律

    初步找大概位置,然后找精确位置,算是简单化的分块吧! #include<cstdio> #include<cstdlib> #include<iostream> u ...

  10. Mybatis,Spring,SpringMVC框架面试题

    Mybatis测试 1,   Mybatis的核心是(  sqlsessionfactory    ) 2,   使用Mybatis持久化框架进行数据查询需要返回的一个实体类的集合, 在<sel ...