HDU4071 Trick or Treat 二分
来源:互联网 发布:mac截取视频 编辑:程序博客网 时间:2024/04/29 12:56
Problem Address:http://acm.hdu.edu.cn/showproblem.php?pid=4071
【思路】
二分答案。
假想所有点被一个圆包围着,那么题目就是要求这个最小的圆的半径和圆心坐标(在y轴上)。
对圆的半径进行二分,下限为所有点y值的最大值,上限为3e5(为最大距离)。
对于每一个半径,枚举每一个点。以每个点为圆心作圆,则必定在y轴上得到一个区间,求所有区间的交集。
若交集为空,返回错误,否则取其中点为圆心并返回正确。
由于是special judge,二分精度为1e-9即可。
【代码】
#include <iostream>#include <cmath>using namespace std;#define max(a,b) ((a)>=(b)?(a):(b))const int maxn = 50000;struct node{double x, y;}pt[maxn+5];bool set(double &tl, double &tr, double cl, double cr){if (cl>tr || tl>cr) return false;if (tr>cr) tr = cr;if (tl<cl) tl = cl;return true;}bool ok(double r, int n, double &p){int i;double r2 = r*r;double td, tl, tr;td = sqrt(r2-pt[0].y*pt[0].y);tl = pt[0].x - td;tr = pt[0].x + td;for (i=1; i<n; i++){td = sqrt(r2-pt[i].y*pt[i].y);if (!set(tl, tr, pt[i].x-td, pt[i].x+td))return false;}p = (tl+tr)/2;return true;}void solve(int n, double &p, double &d){double low = 0, high = 3e5;int i;for (i=0; i<n; i++) low = max(low, fabs(pt[i].y));double mid;while(fabs(high-low)>1e-9){mid = (low+high)/2;if (ok(mid, n, p)){d = mid;high = mid;}else low = mid;}}int main(){int n;int i;double p, d;while(scanf("%d", &n)!=EOF){if (n==0) break;for (i=0; i<n; i++) scanf("%lf %lf", &pt[i].x, &pt[i].y);solve(n, p, d);printf("%.9lf %.9lf\n", p, d);}return 0;}
- HDU4071 Trick or Treat 二分
- ZOJ 3368 Trick or Treat(二分答案)
- 3592 - Trick or Treat!
- POJ3873 Trick or Treat
- Trick or Treat
- PKU Trick or Treat
- ZOJ Trick or Treat //三分查找
- BNUoj 4260 Trick or Treat (三分)
- bnuoj Trick or Treat(三分查找)
- [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果
- zoj 3386 Trick or Treat 三分 求最大值的 最小值
- BNU 4260 Trick or Treat && ZOJ 3386 (三分查找)
- 【三分查找求单峰函数的最值】 ZOJ 3386 Trick or Treat
- 【BZOJ1589】【USACO 2008 Dec Gold】 1.Trick or Treat on the Farm 基环树裸DP、
- 洛谷P2921/BZOJ1589[USACO08DEC]在农场万圣节Trick or Treat on the Farm
- BZOJ1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果
- bzoj[Usaco2008 Dec]Trick or Treat on the Farm 采集糖果 tarjan
- BZOJ 1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果 记忆化搜索
- PS5图案生成器
- C# 文件操作之 StreamReader & StreamWriter
- 插入排序
- android+unity3D游戏开发之简单的碰撞检测
- (4)cdev_alloc和cdev_add
- HDU4071 Trick or Treat 二分
- TextBox字数限制
- 昨晚来我家看我的S5pv210的 人,怎么会这么现实?
- 使用VS2005配置CodeBlocks
- 常用ASCII码 及 ASCII码表(全)
- 11.5 Theme创建及应用
- tftp无法连接错误总结
- 模板页的应用
- Linux下防火墙关闭方法