hdoj 2199 Can you solve this equation? 【二分枚举】
题意:给出一个数让你求出等于这个数的x
策略:如题。因为整个式子是单调递增的,所以可以用二分。
要注意到精度.
代码:
#include <stdio.h>
#include <string.h>
#include <math.h>
#define eps 1e-10
#define f(x) 8*pow(x, 4) + 7*pow(x, 3) + 2*pow(x, 2) + 3*x
int main()
{int t;double n;scanf("%d", &t);while(t --){scanf("%lf", &n);n-=6;double max = f(100);if(n<0||n>max){printf("No solution!\n");continue;}double left, right, mid;left = 0; right = 100;while(right-left > 1e-7){ //精度要小于1e-7,mid = (left+right)/2;double temp = f(mid);if(temp < n) left = mid+1e-7;else right = mid;}printf("%0.4lf\n", left);}return 0;
}
hdoj 2199 Can you solve this equation? 【二分枚举】相关推荐
- hdu 2199 Can you solve this equation? 二分
1.精度问题 由于是double类型,r=mid 而不是r=mid-1 2.如果首位两端(f(0)和f(100))同号,证明解不在[1,100]区间内 这是我之所以TE的原因,没有预先判断 3.若在这 ...
- HDOJ 2199 HDU 2199 Can you solve this equation? ACM 2199 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=2199 ...
- HDU 2199 Can you solve this equation?【二分查找】
解题思路:给出一个方程 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,求方程的解. 首先判断方程是否有解,因为该函数在实数范围内是连续的,所以只需使y的值满足f(0)< ...
- UVA10341 Solve It【二分】
Solve the equation: p ∗ e−x + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x2 + u = 0 where 0 ...
- HDOJ---2236 无题II[二分枚举+匈牙利]
无题II Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- [Codeforces Round #635 (div2)]1337D - Xenia and Colorful Gems[二分][枚举]
1337D - Xenia and Colorful Gems[二分][枚举] time limit per test memory limit per test input output 3 sec ...
- 二分枚举+贪心(nyist疯牛)
点我啊~带你去找它\(^o^)/~ 一开始一点思路都没有,压根不知道它要求的是什么,然后问了一下班长,才明白题目的意思就是,给你N个点,要你找出最优解的C点,言简意赅的即使说区间选点. 思路: 假设两 ...
- poj 2455 Secret Milking Machine(二分枚举+最大流)
题意: 题意:FJ有N块地,这些地之间有P条双向路,每条路的都有固定的长度l.现在要你找出从第1块地到第n块地的T条不同路径,每条路径上的路不能与先前的路径重复,问这些路径中的最长路的最小是多少. 思 ...
- Brownie Slicing(二分枚举答案)
描述 Bessie has baked a rectangular brownie that can be thought of as an RxC grid (1 <= R <= 500 ...
最新文章
- Json 学习 JSONObject 和 JSONArray
- [Redis]Redis章2 Redis 持久化
- Cannot evaluate tensor using 'eval' No default session is registered错误问题的解决
- GLSL实现滤镜效果
- Delphi资源文件的应用(转)
- wxWidgets:wxChoicebook类用法
- Flink + Iceberg 在去哪儿的实时数仓实践
- Swift 学习手记1,pod 的 类库使用
- 用JavaScript怎么实现页面跳转 类:具有相同特征的事物的种类。http://zhidao.baidu.com/question/133995150.html...
- 基于PCL的ICP及其变种算法实现
- 物联网卡如何帮助农民提高收益
- 点击按钮测试用例标题_如何才能设计出高质量的测试用例
- 什么是tftp服务器? 如何搭建tftp服务器?
- 在东京,月薪25万日元能过上什么样的日子啊
- codecademy SQL 编程系列二 Relation Databases Statements
- jquery对cookie进行读取、写入和删除
- 微信公众号注册操作流程
- web前端开发主要培训哪些内容
- Monaco-Editor 多人协作 编辑器
- 基于Ubuntu+Bochs模拟器实现的操作系统图形化的小游戏(2048、flappybird、)