三分求极值
来源:互联网 发布:矩阵奇异值分解例题 编辑:程序博客网 时间:2024/05/16 01:53
1142 : 三分·三分求极值
题目传送:hihoCoder - 1142 - 三分·三分求极值
二分适用于单调函数,对于需要逼近的区间做二等分,来求解某点的值等。
三分适用于凸形函数,对于需要逼近的区间做三等分。
AC代码:
#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <complex>#include <cstdlib>#include <cstring>#include <fstream>#include <sstream>#include <utility>#include <iostream>#include <algorithm>#include <functional>#define LL long long#define INF 0x7fffffffusing namespace std;double a, b, c, x, y;double get_dist(double xx) { double yy = a * xx * xx + b * xx + c; return sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));}int main() { double l = -500, r = 500; scanf("%lf %lf %lf %lf %lf", &a, &b, &c, &x, &y); while(r - l > 0.000001) {//这里为了保证精度,尽量开小点,因为是分治,即使再小也能够承受 double d = (r - l) / 3; double rm = r - d; double lm = l + d; if(get_dist(lm) < get_dist(rm)) { r = rm; } else l = lm; } printf("%.3lf\n", get_dist(l)); return 0;}
0 0
- poj3737_三分求极值
- [HDU3400]三分求极值
- 三分求极值
- 三分求极值
- 求极值--三分
- #1142 : 三分·三分求极值 ( 三分极值 )
- 【三分求极值】hdu 3714
- (求极值)三分模板
- hdu 4717(三分求极值)
- hihoCoder #1142 : 三分求极值
- poj 3301 三分求极值
- ZCMU-1682-三分求极值
- hihoCoder 1142 三分求极值
- #1142 : 三分·三分求极值
- hihocoder 1142 三分·三分求极值
- hihocoder 1142 : 三分·三分求极值
- hiho 40 三分·三分求极值
- hiho 40 ->三分·三分求极值
- js面向对象分页器
- ckplayer播放器怎么去掉右边的开关灯分享插件
- 善有善报,恶有恶报?
- IOS (null )和<null>的处理
- 关于09网易软测题目个人测试思路总结
- 三分求极值
- OpenCV_Python学习笔记--OpenCV中的绘图函数
- ViewPager和Tabhost结合,可滑动的tabhost
- POI实战-java开发excel详解之常用操作-注释
- Ubuntu配置nginx+php
- Google Python Class 学习笔记(1) Introduce String list del
- 使用正则表达式进行匹配
- 【Android】实现联系人效果
- curl 返回CURLE_COULDNT_RESOLVE_HOST、CURLE_COULDNT_CONNECT