Toj 3777 Function Problem
来源:互联网 发布:程序员的技术栈 编辑:程序博客网 时间:2024/05/22 13:09
Total Runs: 437 Accepted Runs:121
Description
We define a function Y = Ax2 + Bx +C; (0 ≤A ≤ 100, 0 ≤ |B| ≤ 5000, |C| ≤ 5000).
Now we have two functions Y1, Y2. We define a new function F(x), The value of F(x) is F(x0) = max(Y1(x =x0),Y2(x = x0)), whenx =x0. If you know the value of A, B, C of the two function, calculate the minmum value of F(x0) (0 ≤x0 ≤ 1000).
Input
There are multiple test cases, first line is the case number T (T ≤ 100). Every case has two lines, every line has three integers, the value ofA,B, C of the two functions (0 ≤ A ≤ 100, 0 ≤ |B| ≤ 5000, |C| ≤ 5000).
Output
Output a real number on line, Four decimal places reserved.
Sample Input
22 0 02 0 02 0 02 -4 2
Sample Output
0.00000.5000
Note: Special judge problem, you may get "Wrong Answer" when output in wrong format.
题目大意:给定两个开口向上的二次函数,求对于所有相同的x(0~1000)两个函数中较大的一个的值的最小值。(有点绕,但是应该很容易理解)
解题思路:(一开始以为要用二次函数各种公式,太傻了)正确的解题思路是利用三分搜索,不断缩小范围,找到最小值的一个近似值。
三分搜索类似二分搜索的思想,只是二分只适用于单调函数,而三分适用于凹凸函数。
话不多说,上代码(用的循环而没有使用递归,就这道题来说,递归也ok):
#include<stdio.h>#include<iostream>#include<iomanip>#include<cmath>#include<algorithm>using namespace std;double a1,b1,c1,a2,b2,c2;double f(double e){ return max( a1*e*e+b1*e+c1,a2*e*e+b2*e+c2);} int main(){int t;cin>>t;while(t--){cin>>a1>>b1>>c1>>a2>>b2>>c2;double left=0,right=1000;while(right-left>=1e-8){double mid1=left+(right-left)/3, mid2=right-(right-left)/3; if(f(mid1)<f(mid2)+1e-8){ right=mid2; } else left=mid1;}cout<<fixed<<setprecision(4)<<f(left)<<endl;} return 0;}
- Toj 3777 Function Problem
- TOJ 3777.Function Problem(三分基础题目)
- TOJ 3777Function Problems 三分法的应用
- [TOJ 4124] Function
- TOJ 10006 Josephus Problem
- TOJ A+B Problem
- TOJ 3761 Egg Problem
- toj 2867. Picking Problem
- TOJ 4112 Counting problem
- TOJ 2821.Grouping Problem
- TOJ 1753.Hamming Problem
- TOJ 1626. Function Run Fun
- TOJ 4107 A simple problem
- TOJ 4109 Cyuunibyou's problem
- TOJ 2793.A Simple Problem
- ACM TOJ 1283 A DP Problem
- 【TOJ 3701.】A Pungent Problem【树链刨分】
- 【贪心】 TOJ 4121. Muxiaokui's Problem
- 7.7.1用穷举法计算两个正整数的最大公约数
- 利用休息时间编写的关于新唐单片机较为简单的ADC+定时器+IO端口程序
- golang调用lua脚本
- idea 误删文件恢复
- Introduction to Linear Algebra 学习笔记(一)
- Toj 3777 Function Problem
- Java培训总结-第1周
- bzoj1026 [SCOI2009]windy数
- opencv3/C++视频背景建模
- HTML 5概述
- SCRAPY_part4_Items
- 长期失眠如何调理?经常熬夜的朋友的福音来了。
- AMH面板彻底删除网站的方法
- shell版俄罗斯方块