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. linux下构建SVN

    1. 安装subversion#yum -y install subversion2. 安装好了之后 新建一个svn目录#mkdir /home/svn3. 新建两个版本仓库#svnadmin cre ...

  2. MySQL常用API函数

    -- 返回数字的绝对值 SELECT ABS(-10) -- 返回不大于X的最大整数值 SELECT FLOOR(10.9) -- 返回不小于X的最大整数值 SELECT CEILING(10.4) ...

  3. 配置RedisTemplate、JedisPoolConfig、JedisConnectionFactory+自定义序列化 (xml+java方式)+使用

    java方式配置RedisTemplate //spring注入ben //@Bean(name = "redisTemplate") public RedisTemplate i ...

  4. windows下如何安装pip以及如何查看pip是否已经安装成功?

    最近刚学习python,发现很多关于安装以及查看pip是否安装成的例子都比较老,不太适合于现在(python 3.6 )因此,下一个入门级别的教程. 0:首先如何安装python我就不做介绍了. 1: ...

  5. python -- @classmethod @staticmethod区别和使用

    python中的定义: class MyClass: ... @classmethod  # classmethod的修饰符 def class_method(cls, arg1, arg2, ... ...

  6. qt+vs2005新建配置不自动加载Generated Files进工程(个人备份)

    工程右键Qt Project Settings 的Moc Directory路径删除 确定,再进入将删除路径加上

  7. flask总结之session,websocket,上下文管理

    1.关于session flask是带有session的,它加密后存储在用户浏览器的cookie中,可以通过app.seesion_interface源码查看 from flask import Fl ...

  8. AJAX上传文件到服务器

    上传文件是常要处理的事情,使用ajaxFileUpload.js处理比较方便,这里的ajaxFileUpload.js文件修改过的, Html部分 <input type="file& ...

  9. 04.nginx使用

    博客为日常工作学习积累总结: 1.安装依赖包 安装pcre :yum install pcre pcre-devel -y        安装openssl:yum install openssl o ...

  10. layui layer.open() 弹层开启后 Enter回车 遮罩层无限弹处理

    解决方案: 增加success回调及其内容 如下: layer.open({ title:'更新论坛信息', type: 1, skin: 'layui-layer-rim', area: ['500 ...