解题思路:给出一个方程 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,求方程的解。 首先判断方程是否有解,因为该函数在实数范围内是连续的,所以只需使y的值满足f(0)<=y<=f(100),就一定能找到该方程的解,否则就无解。 然后是求解过程, 假设一个区间[a,b],mid=(a+b)/2,如果f(a)*f(b)<0,那么函数f(x)在区间[a,b]至少存在一个零点,如果f(a)<0,说明0点在其右侧,那么将a的值更新为当前mid的值,如果f(a)>0,说明0点在其左侧,将b的值更新为mid的值。画出图像更好分析。

Can you solve this equation?

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9490    Accepted Submission(s): 4382

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!

#include<stdio.h>
#include<string.h>
double f(double x)
{
return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
}
int main()
{
int ncase;
double y,ans,left,right,mid;
scanf("%d",&ncase);
while(ncase--)
{
scanf("%lf",&y);
ans=0;
left=0;
right=100;
if(f(0)<=y&&y<=f(100))
{
while(right-left>0.000000001)
{
{
mid=(left+right)*0.5;
ans=f(mid);
if(ans-y<0)
left=mid;
else
right=mid;
}
}
printf("%.4lf\n",mid);
}
else
printf("No solution!\n");
}
}

  

HDU 2199 Can you solve this equation?【二分查找】的更多相关文章

  1. HDU 2199 Can you solve this equation?(二分精度)

    HDU 2199 Can you solve this equation?     Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == ...

  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? 二分

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

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

  6. HDU 2199 Can you solve this equation?(二分解方程)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/10 ...

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

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

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

  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. Robot Framework(二)测试数据语法

    2.1.1文件和目录 测试数据的层次结构安排如下: 测试数据在测试数据文件中创建. 测试数据文件会自动创建一个包含该文件中的测试数据的测试套件. 包含测试数据文件的目录构成了更高级别的测试套件.这样的 ...

  2. IdentityServer4-HybridAndClientCredentials

    一.服务器 Client设置: new Client { ClientId = "mvc1", ClientName = "后台管理MVC客户端", Clien ...

  3. mDNS 原理的简单理解

    转自:http://www.binkery.com/post/318.html mDNS 原理的简单理解 mDNS multicast DNS , 使用5353端口. 在局域网内,你要通过一台主机和其 ...

  4. 配置mysql允许远程访问

    1.进入 mysql: /usr/local/mysql/bin/mysql -u root -p 2.使用 mysql库 : use mysql; 3.查看用户表 : SELECT `Host`,` ...

  5. ongl表达式中得到对象,调用对象方法(OA项目权限显示模块)

    在用户是否拥有某项权限的问题  是这样解决的: 用户登录之后  登录信息是保存在session域中的  通过el表达式可得到登录的对象信息  那么怎样判断用户是否拥有某项权限呢 ?如果没有上图中的判断 ...

  6. JSON 基础学习1

    http://www.360doc.com/content/10/0809/22/2633_44873063.shtml JSON转字符串: json.stringify(jsonobj); 字符串转 ...

  7. js 现给数字加三位一逗号间隔的种方法

    方法一:(ie下有问题) <script type= "text/javascript"> var num_s = "1232134456.546 " ...

  8. 0108MySQL集群搭建详解(三种结点分离)

    转自http://blog.csdn.net/yang1982_0907/article/details/20716845,感谢博主 本文将搭建一个最简化的MySQL Cluster系统,配置方法中的 ...

  9. jquery-ajax基础-XMLHttpRequest

    XMLHttpRequest知识点 原生的ajax代码 var xmlhttp; // 声明一个对象 if (window.XMLHttpRequest) {// code for IE7+, Fir ...

  10. 数据库-mongodb-常用命令

    展示当前集合列表 1 show dbs 查看查询命令 1 db.stu.find().explain(); 结果中的 "cursor":"BasicCursor" ...