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. 【SQL】- 基础知识梳理(六) - 游标

    游标的概念 结果集,结果集就是select查询之后返回的所有行数据的集合. 游标(Cursor): 是处理数据的一种方法. 它可以定位到结果集中的某一行,对数据进行读写. 也可以移动游标定位到你需要的 ...

  2. myeclipse一些快捷键 错了或者没说到补充下

    Ctrl + 1 快速修复Ctrl + D  删除当前行 Ctrl + Alt + ↓ 复制当前行到下一行(复制增加)Ctrl + Alt + ↑ 复制当前行到上一行(复制增加)Alt + ↓ 当前行 ...

  3. Opengl4.5 中文手册—C

    索引 A      B    C      D     E     F     G H      I    J      K     L     M     N O      P    Q      ...

  4. python 脚本开发实战-当当亚马逊图书采集器转淘宝数据包

    开发环境python2.7.9 os:win-xp exe打包工具pyinstaller 界面tkinter ============================================= ...

  5. SSM框架—详细整合教程(Spring+SpringMVC+MyBatis)

    很久没有新搭建过框架了,今天搭建一遍.以往都是在eclipse中搭建,今天换Idea吧,目前来说Idea用的还是很多的,但是用习惯了eclipse的朋友,可能会不太习惯 ok.....开始: 注意区分 ...

  6. java枚举类(enum) 基础知识讲解

    枚举类是在java 5后新增的,可以用于封装常量,并且还可以为常量的使用提供一些方法. 定义枚举类的语法: public enum EnumName{ 成员1(A,B...),成员2(A,B...), ...

  7. 用css绘制各种图形

    1.用css绘制三角形 http://www.cnblogs.com/blosaa/p/3823695.html

  8. 洗礼灵魂,修炼python(1)--python简介

    首先,本人也是刚接触python短短几个月,没有老鸟的经验和技能,大佬勿喷,以下所有皆是本人对python的理解 python,是一种解释型(高级)的,面向对象的,带有动态语义的高级程序设计的开源语言 ...

  9. javascript的数值转换 number()详解

    ---恢复内容开始--- number() parseInt() parseFloat()这三个函都可以把数非数值转换为数值,我们看看他们的区别在哪里 一 Number() 转型函数Number()是 ...

  10. jquery事件使用方法总结

    jquery提供了许多的事件处理函数,学习前端一段时间了,下面对其总结一下,梳理一下知识点. 一.鼠标事件 1. click():鼠标单击事件 $div = $("div") $d ...