Can you solve this equation?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 25633    Accepted Submission(s): 11018

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!

题意:知道y值,要求算出x。并且x只能在0~100之间,不然就输出No solution!

题解:因为x只能在0~100之间。所以在知道y值得情况下判断有没有解的方法是:如果给出的Y值比f(0)还小,那他肯定没有0~100之间的解。因为解在0~100之间都是正数。同理也不能大于f(100);

其实上面的可以用这个函数在0~100之间单调递增来解释,比较清楚

剩下的就是二分来找解,看一下代码还是挺容易理解的

 #include<bits/stdc++.h>
using namespace std;
double f(double x)
{
return (*x*x*x*x+*x*x*x+*x*x+*x+);
}
int main()
{ int t;
while(~scanf("%d",&t))
{
while(t--)
{
double y;
scanf("%lf",&y);
if(f()>y||f()<y)
{
printf("No solution!\n");
continue;
}
double l,r;
l=0.0;r=100.0;
double mid=50.0;
while(fabs(f(mid)-y)>1e-)
{
if(f(mid)>y)
{
r=mid;
mid=(l+r)/2.0; }
else
{
l=mid;
mid=(l+r)/2.0;
} }
printf("%.4lf\n",mid);
}
}
return ;
}

hdu2199Can you solve this equation?(解方程+二分)的更多相关文章

  1. [LeetCode] Solve the Equation 解方程

    Solve a given equation and return the value of x in the form of string "x=#value". The equ ...

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

  3. HDU 2199 Can you solve this equation? 【浮点数二分求方程解】

    Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and 100; ...

  4. UVA 10341 Solve It 解方程 二分查找+精度

    题意:给出一个式子以及里面的常量,求出范围为[0,1]的解,精度要求为小数点后4为. 二分暴力查找即可. e^(-n)可以用math.h里面的exp(-n)表示. 代码:(uva该题我老是出现Subm ...

  5. Can you solve this equation?---hdu2199(二分)

    http://acm.hdu.edu.cn/showproblem.php?pid=2199 给出y的值求x: 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 = Y x是0到100的 ...

  6. hdu2899Strange fuction(解方程+二分)

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. HDU 2199 Can you solve this equation(二分答案)

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

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

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

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

随机推荐

  1. 16、SpringBoot-CRUD错误处理机制(3)

    3).将自己指定的数据携带出去 出现错误以后,会来到/error请求,会被BasicErrorController 进行处理 响应出去的数据是由 getErrorAttributes 得到的( Abs ...

  2. 2spring注解:@Lazy,@Conditional,@import,FactoryBean接口

    大致的工程内容也来源于上一篇博文! https://www.cnblogs.com/Mrchengs/p/10108603.html 1.@Lazy懒加载 懒加载:针对单实例的 单实例bean,默认在 ...

  3. 【转】maven命令-P 参数引发的思考

    序言: maven 命令:clean package -Dmaven.test.skip=true -P product 1.命令很简单是:清class文件,打包构建,跳过测试,注意最后一个 -P p ...

  4. java中io创建文件和读取文件

    简单了解IO流:https://www.cnblogs.com/weibanggang/p/10034325.html package com.wbg.iodemo1128; import java. ...

  5. ajax简单做html查询删除(鲜花)

    下载视频+项目链接:https://pan.baidu.com/s/1jUld3-Nqm3fUAzFSX8kjlQ

  6. HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  7. 基于uIP和uC/OS-II嵌入式网络开发

    基于uIP和uC/OS-II嵌入式网络开发 ——uIP主动发送数据分析 摘要:uIP协议栈简单易用,可以为16位单片机或者是更低级的处理器使用,占用的资源很少,相关移植网上有详细介绍,本文主要讨论uI ...

  8. one or more listeners failed to start问题解决思路

    今日搭建一个web应用的时候总是遇到tomcat报错:one or more listeners failed to start. Full detail balabale....而且还没有其他提示, ...

  9. Maven项目改为spring boot项目的方法

    目录树 新建Maven项目及步骤 修改方法 启动测试 新建Maven项目及步骤 我这里是从创建开始讲,使用的工具是Idea2017版本.如果是已经创建了Maven,想改为spring boot项目的请 ...

  10. 使用py2exe将python程序打包成exe程序

    近日帮朋友写了个python小程序,从互联网上抓取一些需要的文章到本地.为了运行方便,希望能转换成exe程序在windows下定期执行.从百度上找了些文章,发现py2exe的应用比较多,遂使用之. 1 ...