[2016-03-05][UVALive][4504][Trick or Treat]

  • 时间:2016-03-05 12:06:59 星期六
  • 题目编号: UVALive 4504 B - Trick or Treat
  • 题目大意:给定坐标轴上若干个点,每个点上有一个人,求x轴上一点,使得所有人到这个点集合所花费的时间最短,所有人同时出发,
  • 输入:
      • 若干组数据,0结束
        •         每组数据
        •         n顶点个数
        •         接下来n行,每个顶点的坐标 double 类型
  • 输出:点的坐标,需要的时间
  • 分析:可以看出,x轴上从左到最优点,到右, 花费的时间 先降低后升高,那么就可以3分坐标点,求出最优的答案

#include <vector>

#include <list>

#include <map>

#include <set>

#include <deque>

#include <queue>

#include <stack>

#include <bitset>

#include <algorithm>

#include <functional>

#include <numeric>

#include <utility>

#include <sstream>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cctype>

#include <string>

#include <cstring>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <ctime>

using namespace std;

typedef long long LL;

#define CLR(x,y) memset((x),(y),sizeof((x)))

const int maxn = 50000 + 100;

int n;

struct Point{

double x,y;

bool operator < (const Point a)const {

return a.x > x;

}

}p[maxn];

double Calc(double x) {

double rtn = 0;

for(int i = 0 ; i < n ;++i){

rtn = max(rtn , sqrt(double(p[i].y * p[i].y + (p[i].x - x) * (p[i].x - x))));

}

return rtn;

}

double Solve(double MIN, double MAX) {

double Left, Right;

double mid = 0, midmid = 0;

double mid_area = 0, midmid_area = 0;

Left = MIN; Right = MAX;

for(int i = 0;i < 150;++i){

mid = (Left + Right) / 2;

midmid = (mid + Right) / 2;

mid_area = Calc(mid);

midmid_area = Calc(midmid);

if (midmid_area - mid_area > eps) Right = midmid;

else Left = mid;

}

return midmid;

}

int main(){

while(~scanf("%d",&n) && n){

for(int i = 0;i < n ;++i)

scanf("%lf%lf",&p[i].x,&p[i].y);

sort(p,p+n);

double res = Solve(p[0].x,p[n - 1].x);

printf("%.7lf %.7lf\n",res,Calc(res));

}

return 0;

}  

来自为知笔记(Wiz)

时间: 2024-08-11 01:35:40

[2016-03-05][UVALive][4504][Trick or Treat]的相关文章

2016/03/05 codes

var tMat = poly1.m_R; normal1X = tMat.col1.x * tX + tMat.col2.x * normal1Y; normal1Y = tMat.col1.y * tX + tMat.col2.x * normal1Y; var normalLocal2X = normal1X; var normalLocal2Y = normal1Y; tMat = poly2.m_R; tX = normalLocal2X * tMat.col1.x + normalL

[BZOJ1589][Usaco2008 Dec]Trick or Treat on the Farm 采集糖果

1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 719  Solved: 408 [Submit][Status][Discuss] Description 每年万圣节,威斯康星的奶牛们都要打扮一番,出门在农场的N(1≤N≤100000)个牛棚里转悠,来采集糖果.她们每走到一个未曾经过的牛棚,就会采集这个棚里的1颗糖果. 农场不大,所以约翰要想尽

分布式技术一周技术动态 2016.03.20

分布式系统实践 1. 基于Mesos和Docker的分布式计算平台 https://mp.weixin.qq.com/s?__biz=MzAxMDgzOTA2Mw==&mid=402769128&idx=1&sn=cea3ad1357bd9312acf1768c0a493bfd&scene=1&srcid=0318BTuxT0fsFYwPjpeyuDOa&key=710a5d99946419d90fbc1e7600cce055b6e997d6afafc74c

[Usaco2008 Dec][BZOJ1589] Trick or Treat on the Farm 采集糖果

1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 438  Solved: 244[Submit][Status][Discuss] Description 每年万圣节,威斯康星的奶牛们都要打扮一番,出门在农场的N(1≤N≤100000)个牛棚里转悠,来采集糖果.她们每走到一个未曾经过的牛棚,就会采集这个棚里的1颗糖果. 农场不大,所以约翰要想尽法子

洛谷 P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm

P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题目描述 Every year in Wisconsin the cows celebrate the USA autumn holiday of Halloween by dressing up in costumes and collecting candy that Farmer John leaves in the N (1 <= N <= 100,000) stalls conven

P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm(Tarjan+记忆化)

P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题意翻译 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定奶牛必须遵循的穿越路线来确保奶牛的乐趣.为了实现这个让奶牛在牛棚里来回穿梭的方案,FJ在第i号隔间上张贴了一个“下一个隔间”Next_i(1<=Next_i<=N),告诉奶牛要去的下一个隔间:这样

Trick or Treat?——***“捣蛋”QAD“发糖”

Dang~Dang~DangTrick or Treat不给糖就捣蛋 万圣节是西方的传统节日,每到万圣节小朋友们都会扮成"牛鬼蛇神"的样子,去敲邻居家的门要糖吃,如果不给糖就会被孩子们捣蛋,扮成小鬼的样子吓人.今天是万圣节之夜,你准备好了吗?(本末有彩蛋哦~) 对企业来说,******就像万圣节的"小鬼"一样,一个猝不及防就让你"崩溃",如何抵御***威胁?信息安全该如何管控?企业要时刻做好"发糖"的准备! 信息安全威胁环境在

【EPM-易通元】2016年05月03日凌晨迎来第6次坼分庆祝

[EPM易通元5月3日凌晨迎来了第6次拆分庆贺] 易通元的家人们幸福啦,么么哒……大家迎来了EPM第六次拆分,股数翻倍,积分又回到0.2美金啦所有参与易通元理财的家人们幸福喽,发财啦……么么哒 “EPM-易通元创始人安德森”先生为了易通元,放弃年薪千万美金在花旗银行的高管工作,就如同当年阿里巴巴蔡崇信放弃汇丰银行年薪580万工作一样,这是常人智慧想不到的! [关于拆分盘客观分析]一.决定拆分盘存活的关键是前面3-6次拆分!二.拆分盘几种结局:1.胎死腹中:    内排,抢先机,未开盘就挂了!2.

PAS 03.05.003 Windows 1CD+ Abaqus v6.14-5+TMG for NX 8.5

Global Mapper v16.0.7.121814 Win32_64 2CD Siemens.LMS Virtual.Lab Rev13.1.Win64 3DVD  PSD to 3D v9.9 1CD Rocscience Slide v6.032 1CD Siemens.NX.v10.0 Engineering DataBases 1DVD SKM.PowerTools .v7.0.2.4 Win8 64bit 1CD  SIEMENS NX v10.0.0 Mold Wizard E