1. 程式人生 > >Trick or Treat

Trick or Treat



Johnny 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 don't 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. Johnny's 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 Johnny's 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 ( 1<=n<=50 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 <= xy <= 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

2
1.5 1.5
3 0

1
0 0

4
1 4
4 4
-3 3
2 4

5
4 7
-4 0
7 -6
-2 4
8 -5

0

Sample Output

1.500000000 1.500000000
0.000000000 0.000000000
1.000000000 5.000000000
3.136363636 7.136363636
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <cmath>

using namespace std;

struct node
{
    double x,y;
}N[512345];

double mr,ml;//比賽的時候又寫成了int!!!
int n;

int cmp(node a,node b)
{
    if(a.x != b.x)
    return a.x < b.x;
    else
    return a.y < b.y;
}

double judge(double i)
{

    double m =0.0;
    for(int j=0;j<n;j++)
    {
        double yy = sqrt((N[j].x - i)*(N[j].x - i)+(N[j].y)*(N[j].y));
        if(yy > m)
        m = yy;
    }
    return m;
}

void sanfen(double l,double r)
{
    double mid,mmid;
    while(r - l >1e-10)
    {
//        cout<<"!"<<endl;
        mid = (l + r)/2;
        mmid = (mid + r)/2;
        double tt1 = judge(mid);
        double tt2 = judge(mmid);
        if(tt1 < tt2) r = mmid;
        else  l = mid;
    }
    printf("%.9lf %.9lf\n",mid,judge(mid));
//    return judge(l) < judge(r) ? l : r;
}

int main()
{
//    freopen("input.txt","r",stdin);
//    int n;
    while(~scanf("%d",&n))
    {
        if(!n)
        break;
        for(int i=0;i<n;i++)
        scanf("%lf %lf",&N[i].x,&N[i].y);
        ml = 200005;
        mr = -200005;
//        sort(N,N+n,cmp);
        for(int i=0;i<n;i++)
        {
            if(N[i].x < ml) ml = N[i].x;
            if(N[i].x > mr) mr = N[i].x;
        }
//        cout<<ml<<" "<<mr<<endl;
        sanfen(-200005.0,200005.0);
    }
    return 0;
}

相關推薦

bzoj 1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果

lap size cstring stk 采集 pri out pla reat Description 每年萬聖節,威斯康星的奶牛們都要打扮一番,出門在農場的N(1≤N≤100000)個牛棚裏轉悠,來采集糖果.她們每走到一個未曾經過的牛棚,就會采集這個棚裏的1顆糖果.

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

ems data www. ont ble false 設置 elong col 1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果 Time Limit: 5 Sec Memory Limit: 64 MB Sub

洛谷 P2921 [USACO08DEC]在農場萬聖節Trick or Treat on the Farm

names sco -s fine -c farm 直接 -a rect P2921 [USACO08DEC]在農場萬聖節Trick or Treat on the Farm 題目描述 Every year in Wisconsin th

bzoj 1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果【tarjan+記憶化搜索】

dfs spa 重新 i++ mes RM tar \n () 對這個奇形怪狀的圖tarjan,然後重新連邊把圖變成DAG,然後記憶化搜索即可 #include<iostream> #include<cstdio> using namespace s

p2921 Trick or Treat on the Farm

type return ble getch ron org nbsp 就會 ostream 傳送門 題目 每年萬聖節,威斯康星的奶牛們都要打扮一番,出門在農場的N個牛棚裏轉 悠,來采集糖果.她們每走到一個未曾經過的牛棚,就會采集這個棚裏的1顆糖果。農場不大,所以約翰要想盡法

[USACO08DEC]在農場萬聖節Trick or Treat on the Farm

urn www oot 最短距離 head col reat UC https 題目傳送門 solution 首先看到這題,題目要求回到經過的點,那麽很明顯是形成了一個環,那麽很容易想到是Tarjan,仔細一想,一個點只有兩種情況,要麽在環中,要麽通過一條鏈與環相接。那麽思

洛谷——P2921 [USACO08DEC]在農場萬聖節Trick or Treat on the Farm

badge radius clas 通過 name printf 要去 ret print P2921 [USACO08DEC]在農場萬聖節Trick or Treat on the Farm 題意翻譯 題目描述 每年,在威斯康星州,奶牛們都會穿上衣服,收集農夫約翰在

Luogu 2921 [USACO08DEC]在農場萬聖節Trick or Treat on the Farm

close tar getc cli farm namespace printf pla from 基環樹森林,然而我比較菜,直接tarjan找環。 發現縮點之後變成了DAG,每一個點往下走一定會走到一個環,縮點之後搜一遍看看會走到哪個環以及那個環的編號是多少,答案就是環

P2921 [USACO08DEC]在農場萬聖節Trick or Treat on the Farm(Tarjan+記憶化)

暴搜 autumn -c ons radi range 必須 mic gif P2921 [USACO08DEC]在農場萬聖節Trick or Treat on the Farm 題意翻譯 題目描述 每年,在威斯康星州,奶牛們都會穿上衣服,收集農夫約翰在N(1<

縮點【洛谷P2921】 [USACO08DEC]在農場萬聖節Trick or Treat on the Farm

【洛谷P2921】 [USACO08DEC]在農場萬聖節Trick or Treat on the Farm 題目描述 每年,在威斯康星州,奶牛們都會穿上衣服,收集農夫約翰在N(1<=N<=100,000)個牛棚隔間中留下的糖果,以此來慶祝美國秋天的萬聖節。 由於牛棚不太大,FJ通

Trick or Treat?——***“搗蛋”QAD“發糖”

免費 應用程序 形勢 功能 中國汽車 *** images 兌現 這樣的 Dang~Dang~DangTrick or Treat不給糖就搗蛋 萬聖節是西方的傳統節日,每到萬聖節小朋友們都會扮成“牛鬼蛇神”的樣子,去敲鄰居家的門要糖吃,如果不給糖就會被孩子們搗蛋,扮成小鬼的

Trick or Treat on the Farm

題目描述 每年,在威斯康星州,奶牛們都會穿上衣服,收集農夫約翰在N(1<=N<=100,000)個牛棚隔間中留下的糖果,以此來慶祝美國秋天的萬聖節。 由於牛棚不太大,FJ通過指定奶牛必須遵循的穿越路線來確保奶牛的樂趣。為了實現這個讓奶牛在牛棚裡來回穿梭的方案,FJ在第i號隔間上張貼了一個“下一

[洛谷P2921][USACO08DEC]在農場萬聖節Trick or Treat on the Farm

題目大意:給你一張有向圖,每個點最多一條出邊,問從每個開始,走多少步會到一個已經過的點 題解:$tarjan$縮點,然後建反圖$DP$ 卡點:無   C++ Code: #include <cstdio> #include <algorithm> #def

Trick or Treat?——黑客“搗蛋”QAD“發糖”

【QAD“發糖” 彩蛋時刻】 QAD萬聖節福利強勢來襲,送給汽車行業的同仁們! AIAG汽車零部件採購高層及供應商峰會 免費入場門票 2018年11月28日 上海虹橋萬豪酒店 活動詳情: 自2007年以來,AIAG(美國汽車行業協會)每年都會舉辦汽車業採購高層

刷題記錄【[USACO08DEC]在農場萬聖節Trick or Treat on the Farm】【NOIP2015資訊傳遞

今天是兩道很相似的圖論水題 1.資訊傳遞 https://www.luogu.org/problemnew/show/P2661 題目描述 有 n個同學(編號為 1 到 n )正在玩一個資訊傳遞的遊戲。在遊戲裡每人都有一個固定的資訊傳遞物件, 其中,編號為 i 的同學的資訊傳遞物件是

【洛谷P2921】Trick or Treat on the Farm

題目大意:給定一個 N 個節點的內向樹森林,求從每個頂點出發能夠到達的最多不重複頂點的個數是多少。 題解:內向樹森林是由一個或若干個環加若干條鏈構成。可以先按照類似於拓撲排序的規則進行刪鏈,再對環上的點計算答案,最後計算鏈上的答案即可。 程式碼如下 #include <bits/stdc++.h&

Trick or Treat HDU

題目:Johnny and his friends have decided to spend Halloween night doing the usual candy collection from the households of their village. As

Trick or Treat

 Johnny and his friends have decided to spend Halloween night doing the usual candy collection from the households of their village. As

【三分查詢求單峰函式的最值】 ZOJ 3386 Trick or Treat

         題目大意是:在一個平面上有N個點,每個點的座標已經給出,現在要求在X軸上找一個點,使得這個點到所有點中最大的距離最小。          分析:我們設這個點為X0,所求的距離為F(x),那麼對於所有的 X < X0 和 X > X0 都有F(x)

【USACO08DEC】在農場萬聖節Trick or Treat on the Farm(縮點+記憶化搜尋)

其實就是一張圖 可知每個點出度為一 由於有環 所以把整個圖縮點後會好做得多 在縮點後 每個強聯通分量的出度至多為一。 然後我們dfs 直接搜很危險 考慮記憶化 設ans[i]代表第i個強連通分量的答案就好了 詳見程式碼 // luogu-judger-enable-o2 #include<bits/st