



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【标准化说明】三分查找技术与简单应用 三分查找技术适用于答案在某一个区间内,这个区间的特点的是,以答案为分点的两侧区间都单调的增大或者减小:如右图就是一个分的例子:三分的区间为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福建省市场监督管理局直属事业单位招聘高层次人才20人模拟试卷附答案详解(黄金题型)
- 2025年甘肃省兰州市肺科医院招聘工作人员14人考前自测高频考点模拟试题及参考答案详解一套
- 2025年上海市城市规划设计研究院招聘高层次专业技术人员考前自测高频考点模拟试题附答案详解(突破训练)
- 2025河南中医药大学人事代理工作人员招聘13人模拟试卷及完整答案详解一套
- 2025广西玉林市北流市大伦镇便民服务中心招聘公益性岗位模拟试卷及一套参考答案详解
- 2025湖南凤凰县直机关事业单位选调40人考前自测高频考点模拟试题及答案详解(典优)
- 2025年甘肃科源电力集团有限公司高校毕业生招聘40人(第三批)考前自测高频考点模拟试题及答案详解(新)
- 2025年滨州邹平怀远学校教师模拟试卷及参考答案详解1套
- 2025湖南郴州飞天山翠江旅游景区多岗招聘考前自测高频考点模拟试题及1套完整答案详解
- 2025年铁总服务有限公司应届高校毕业生招聘考前自测高频考点模拟试题带答案详解
- 2025贵州贵阳市投资控股集团房地产置业有限公司招聘12人考试参考题库及答案解析
- 免疫细胞治疗安全性评价-第1篇-洞察及研究
- 车间师带徒管理办法
- 桥梁工程监理工作实施方案
- 2025年秋期新教材部编人教版一年级上册道德与法治教学计划+进度表
- 服装辅料基础知识培训
- 医院门诊急诊统筹管理方案
- 国家事业单位招聘2025农业农村部国际交流服务中心招聘拟聘用人员笔试历年参考题库附带答案详解
- 2025年AI技术在项目管理中的应用洞察报告
- 胃肠外科医生进修汇报
- 慢病健康宣教课件
评论
0/150
提交评论