hdu2199Can you solve this equation?(解方程+二分)
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
Now please try your lucky.
题意:知道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?(解方程+二分)的更多相关文章
- [LeetCode] Solve the Equation 解方程
Solve a given equation and return the value of x in the form of string "x=#value". The equ ...
- 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? 【浮点数二分求方程解】
Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and 100; ...
- UVA 10341 Solve It 解方程 二分查找+精度
题意:给出一个式子以及里面的常量,求出范围为[0,1]的解,精度要求为小数点后4为. 二分暴力查找即可. e^(-n)可以用math.h里面的exp(-n)表示. 代码:(uva该题我老是出现Subm ...
- 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的 ...
- hdu2899Strange fuction(解方程+二分)
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 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?【二分查找】
解题思路:给出一个方程 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,求方程的解. 首先判断方程是否有解,因为该函数在实数范围内是连续的,所以只需使y的值满足f(0)< ...
- HDU 2199 Can you solve this equation? (二分 水题)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- centos7 firewall指定IP与端口访问(常用)
1.启动防火墙 systemctl start firewalld.service 2.指定IP与端口 firewall-cmd --permanent --add-rich-rule="r ...
- logback配置与使用(2)
转载:yaoh371 的logback.xml常用配置 <?xml version="1.0" encoding="UTF-8"?> <!-- ...
- Parallel.ForEach使用示例
新建一个.NET Core控制台程序,代码如下: using System; using System.Collections.Generic; using System.Threading; usi ...
- 在js中获取到的页面元素为undefined
在学习js的过程中发现了一个问题就是:在js代码中获取页面元素进行操作的时候发现怎么都没有效果,控制台也不报错,弹出获取的元素结果发现是undefined类型. 后来查找了资料发现:因为我的js是写在 ...
- OCR
谷歌OCR光学字符识别窥探 - 简书 Tesseract OCR初探 利用Tesseract图片文字识别初探 _ TonyDeng's Blog Tesseract OCR(光学字符识别)教程 - C ...
- Ajax请求(415 Unsupported Media Type)
Unsupported media type-415(不支持的媒体类型) 该错误类型是后台接收参数为json类型的,然而ajax提交的类型不对,如下: 异常代码: $.ajax({ url: api ...
- MySQL学习之用户管理
用户权限管理 用户权限管理:在不同的项目中给不同的角色(开发者)不同的操作权限,为了保证数据库数据的安全. 简单点说:有的用户可以访问并修改这个数据,而有些用户只能去查看数据,而不能修改数据.就如同博 ...
- Spring Boot 微信-验证服务器有效性【转】
转:https://blog.csdn.net/jeikerxiao/article/details/68064145 概述 接入微信公众平台开发,开发者需要按照如下步骤完成: 在自己服务器上,开发验 ...
- 误操作yum导致error: rpmdb解决方法
错误:[root@test ~]# yum makecache error: rpmdb: BDB0113 Thread/process 18967/139716328294400 failed: B ...
- 08JavaScript对象
JavaScript 对象是拥有属性和方法的数据. 注:在 JavaScript 中,对象是非常重要的,当你理解了对象,就可以了解 JavaScript . 1.JavaScript 对象 在 Jav ...