文章目录
- 前言
- 题目
- 思路
- 代码
前言 这种题没做过,但考试时想得差不多了…
题目 CF传送门
题目大意
现在有n个点,坐标分别为 ( x i , y i ) (x_i,y_i) (xi?,yi?),现在求一个最小半径的圆,使得包含所有点且和 x x x轴相切(只有一个交点),
若不存在,输出-1
答案精确到 1 0 ? 6 10^{-6} 10?6
? 1 0 7 < = x i , y i < = 1 0 7 , y i ! = 0 -10^7< =x_i,y_i< =10^7,y_i!=0 ?107<=xi?,yi?<=107,yi?!=0
i n p u t input input
1
0 1
o u t p u t output output
0.5
i n p u t input input
3
0 1
0 2
0 -3
【CodeForces|Nature Reserve(Codeforces Round #514 (Div. 2)-1060E)(三分答案,数学)】 o u t p u t output output
-1
i n p u t input input
2
0 1
1 1
o u t p u t output output
0.625
思路 首先,我们知道,只要x轴两侧各有点,则输出-1.
我们记圆心为 ( X , r ) (X,r) (X,r)由于和x轴相切,则半径为r,对于每一个点 ( x i , y i ) (x_i,y_i) (xi?,yi?)
文章图片
都有:
( X ? x i ) 2 + ( r ? y i ) 2 < = r 2 (X-x_i)^2+(r-y_i)^2< =r^2 (X?xi?)2+(r?yi?)2<=r2
我们只能从化简式子入手了:
X 2 ? 2 x i X + x i 2 + r 2 ? 2 r y i + y i 2 < = r 2 X^2-2x_iX+{x_i}^2+r^2-2ry_i+{y_i}^2< =r^2 X2?2xi?X+xi?2+r2?2ryi?+yi?2<=r2
化简一下,把r移到左边:
X 2 ? 2 x i X + x i 2 + y i 2 2 y i < = r \frac{X^2-2x_iX+{x_i}^2+{y_i}^2}{2y_i}< =r 2yi?X2?2xi?X+xi?2+yi?2?<=r
也就是说,如果我们有确定的 X X X,那么:
r = m a x { ( X ? x i ) 2 + y i 2 2 y i } r=max\{\frac{(X-x_i)^2+{y_i}^2}{2y_i}\} r=max{2yi?(X?xi?)2+yi?2?},我们就有确定的 r r r
我们又发现,对于答案所在的X,在它左右走 r r r都会单调递增,形成形状像山谷的形状,那么直接三分 X X X找谷底即可
代码
#include
#include
推荐阅读
- AIoT(人工智能+物联网)|程序员的数学【线性代数基础】
- codeforces B. Young Explorers
- codeforces C. Mere Array
- codeforces D. Omkar and Bed Wars
- codeforces C. Omkar and Waterslide
- codeforces B. Omkar and Infinity Clock
- codeforces B. Ternary Sequence
- topcoder|Topcoder SRM 661 Div1 Easy: MissingLCM
- HDU 5184 Brackets (卡特兰数)
- 题库-CF|【Codeforces Round 370 (Div 2) E】【线段树 等比数列 区间合并】Memory and Casinos 赌场区间[l,r] l进r先出的概率