HDU 2199 Can you solve this equation?【二分查找】
解题思路:给出一个方程 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?【二分查找】的更多相关文章
- 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 == ...
- HDU 2199 Can you solve this equation? (二分 水题)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU - 2199 Can you solve this equation? 二分 简单题
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 2199 Can you solve this equation? 二分
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 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 ...
- 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 ...
- 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 ...
- HDU 2199 Can you solve this equation(二分答案)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- Js中的4个事件
除了加载文档的事件onload和鼠标相关的一些事件如onclick,onmouseover等.js还有一些相对不常用的事件,这些事件也有各自的应用场景,本文就介绍 onkeydown,oncontex ...
- Laravel 查询某天数据 whereDate
- WPF 创建用户控件并引用
项目源码地址:https://github.com/lizhiqiang0204/WpfControlLibrary.git 首先创建新项目->WPF用户控件库项目 在UserControl1. ...
- 团体程序设计天梯赛-练习集-L1-026. I Love GPLT
L1-026. I Love GPLT 这道超级简单的题目没有任何输入. 你只需要把这句很重要的话 —— “I Love GPLT”——竖着输出就可以了. 所谓“竖着输出”,是指每个字符占一行(包括空 ...
- python tips:类与实例的属性问题
实例是具象化的类,它可以作为类访问所有静态绑定到类上的属性,包括类变量与方法,也可以作为实例访问动态绑定到实例上的属性. 实例1: class A: work = list("hello&q ...
- leetCode 929 独特的电子邮件地址
题目: 每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而 leetcode.com 是域名. 除了小写字母 ...
- 小松之LINUX 驱动学习笔记(开篇)
时间对每个人都是公平的,就看你怎么对待他.每天多努力一点,未来就会轻松一点.作为一名北漂,感受着首都的压力,也曾萌生过逃离北上广的想法,但是,最后我最终还是选择留下来,随着年龄的增长,我已经没有那么多 ...
- c++之vector使用
Vector是向量模板,C++ STL之一(本质上是一个动态数组).vector是一个动态生长的数组,一开始vector为空时,会给一个初始化的容量 (就是允许的添加个数并申请好内存),当往添加的元素 ...
- spring md5 加密
一.spring 自带的 DigestUtils 工具类可以进行 md5 加密 //导入包 import org.springframework.util.DigestUtils; //对密码进行 m ...
- jdk环境变量设置理解
1.系统变量→新建 JAVA_HOME 变量 . 变量值填写jdk的安装目录(本人是 E:\Java\jdk1.7.0) 2.系统变量→寻找 Path 变量→编辑 在变量值最后输入 %JAVA_HOM ...