




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【标准化说明】三分查找技术与简单应用 三分查找技术适用于答案在某一个区间内,这个区间的特点的是,以答案为分点的两侧区间都单调的增大或者减小:如右图就是一个分的例子:三分的区间为l,r 其中最低点为答案每次把区间分为3个等分取x1=l+(r-l)/3 ,x2=r-(r-l)/3 作为分点,看谁更接近标准答案,并以此来更新左右区间,继续进行二分,直到得到(无限逼近)答案。Trick or TreatDescriptionJohnny and his friends have decided to spend Halloween night doing the usual candy collection from the households of their village. As the village is too big for a single group to collect the candy from all houses sequentially, Johnny and his friends have decided to split up so that each of them goes to a different house, collects the candy (or wreaks havoc if the residents dont give out candy), and returns to a meeting point arranged in advance. There are n houses in the village, the positions of which can be identified with their Cartesian coordinates on the Euclidean plane. Johnnys gang is also made up of n people (including Johnny himself). They have decided to distribute the candy after everybody comes back with their booty. The houses might be far away, but Johnnys interest is in eating the candy as soon as possible. Keeping in mind that, because of their response to the hospitality of some villagers, some children might be wanted by the local authorities, they have agreed to fix the meeting point by the river running through the village, which is the line y = 0. Note that there may be houses on both sides of the river, and some of the houses may be houseboats (y = 0). The walking speed of every child is 1 meter per second, and they can move along any direction on the plane. At exactly midnight, each child will knock on the door of the house he has chosen, collect the candy instantaneously, and walk back along the shortest route to the meeting point. Tell Johnny at what time he will be able to start eating the candy. Input Each test case starts with a line indicating the number n of houses ( 1n50 000). The next n lines describe the positions of the houses; each of these lines contains two floating point numbers x and y ( -200 000 x, y 200 000), the coordinates of a house in meters. All houses are at different positions. A blank line follows each case. A line with n = 0 indicates the end of the input; do not write any output for this case. Output For each test case, print two numbers in a line separated by a space: the coordinate x of the meeting point on the line y = 0 that minimizes the time the last child arrives, and this time itself (measured in seconds after midnight). Your answer should be accurate to within an absolute or relative error of 10-5. Sample Input 21.5 1.53 010 041 44 4-3 32 454 7-4 07 -6-2 48 -50Sample Output 1.500000000 1.5000000000.000000000 0.0000000001.000000000 5.0000000003.136363636 7.136363636SourceSouthwestern 2009-2010#include #include #include #include using namespace std;const int max_size=50001;struct point_type double x,y;int n;point_type pointmax_size;double l,r; /l-most left point (x_door) r-most right point (x_door)int cnt;void init() cnt=0; int i; for (i=1;i=n;i+) scanf(%lf %lf,&pointi.x,&pointi.y); l=r=point1.x; for (i=2;i=n;i+) if (pointi.xr) r=pointi.x; double E(double x) return x*x;double calc(double x) int i; double temp=0; for (i=1;itemp) temp=sqrt(E(pointi.x-x)+E(pointi.y); return temp;void solve() double _lp,_rp; double dist_l,dist_r; for (;r-l10e-12;) if (+cnt=64) break; _lp=l+(r-l)/3; _rp=r-(r-l)/3; dist_l=calc(_lp); dist_r=calc(_rp); if (dist_ldist_r) l=_lp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 前端技术面试题及答案
- 2025年中国合同法中的漏洞与改进
- 2025员工试用期合同协议书范本「标准版」
- 2025珠宝首饰购销合同范本
- 2025酒店管理租赁合同范本
- 婚内财产协议书范本(正式文本)
- 公告知识培训课件
- 搭建帐篷安全知识培训班课件
- 2025设备租赁合同补充协议范本
- 公司财务知识培训视课件
- 江苏南通开放大学招聘笔试真题2024
- 2025年甘肃省高考历史试卷真题(含答案解析)
- 食堂肉类备货方案(3篇)
- 智能微电网应用技术课件
- DB42T 1497-2019 公路工程地质调绘技术规程
- 光谷华科附小数学试卷
- 中国2030年能源电力发展规划研究及2060年展望
- 外协供应商品质管理制度
- BIM技术在绿色建筑碳足迹计算与优化中的应用研究
- 易制毒考试试题及答案
- 2025至2030中国普惠金融行业产业运行态势及投资规划深度研究报告
评论
0/150
提交评论