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. JSP入门 el表达式

    我们已经知道el是jsp-2.0规范的一部分,tomcat-5.x版本以上都已经能够支持jsp-2.0规范,但在更低版本的tomcat和webphere,weblogic中还是无法使用这一便捷方式. ...

  2. JSP获取input(含正则表达式)

    <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> < ...

  3. php中常用的字符串大小写转换函数实例解释

    PHP字符串处理函数中,最为简单的几个函数,相关解释就不上了,直接看例子. PHP字符串处理函数中,最为简单的几个函数,相关解释就不上了,直接看例子. strtolower函数.strtoupper函 ...

  4. java数据库编程之DAO模式

    第八章:DAO模式 8.1:JDBC封装 为了提高代码的维护性和扩展性,我们使用JDBC进行封装数据, 先定义统一的API,将操作数据的代码抽象到接口中,业务逻辑代码只需要调用这些接口的实现类的对象, ...

  5. dets

    模块说明 提供基于文件的项式存储,项式以元组表示,其中某个位置为键,默认第1位置 Dets为Mniesia所用,后者增加了事务.查询.和分布式支持. Dets文件不能超过2GB. Dets只有set ...

  6. python _winreg模块

    详细资料请参考:https://docs.python.org/2/library/_winreg.html 一.常用函数功能介绍 OpenKey() - 打开一个key ############## ...

  7. 将网页封装成苹果APP的牛逼方法,无需发布到appstore,无需越狱即可安装

    很多小伙伴都在开发自己的app, 有的实现实现比较简单,就是一个h5页面,然后想要打包成app发布出去. 这个想法很单纯 打包生成个app这个是很简单的,网上一堆打包工具,分分钟可以完成 但是... ...

  8. 文件上传之--内存溢出(System.OutOfMemoryException)

    两周前就想把这点经验记录下来了,由于拖延症上身,直到刚才突然想起这件未完成的任务,今天是1024,在这个特别的日子里,祝所有程序猿兄弟姐妹们节日快乐! 上传功能一直很正常,直到上传了个500多兆的文件 ...

  9. Docker入门系列(一):目标和安排

    Docker入门系列(一) 这个系列的教程来源于docker的官方文档,此文档的目的在于一步一步学习docker的使用方法. 这一系列的教程有如下几篇文档: docker安装启动 构建第一个docke ...

  10. 使用Jquery.cookie.js操作cookie

    query.cookie.js是一个基于jquery的插件,点击下载! 创建一个会话cookie: $.cookie(‘cookieName’,'cookieValue’); 注:当没有指明cooki ...