BNU 4260 ——Trick or Treat——————【三分求抛物线顶点】

ial Judge

Prev

Submit Status Statistics Discuss

Next

Type:

None

None
 
Graph Theory
 
    2-SAT
 
    Articulation/Bridge/Biconnected Component
 
    Cycles/Topological Sorting/Strongly Connected Component
 
    Shortest Path
 
        Bellman Ford
 
        Dijkstra/Floyd Warshall
 
    Euler Trail/Circuit
 
    Heavy-Light Decomposition
 
    Minimum Spanning Tree
 
    Stable Marriage Problem
 
    Trees
 
    Directed Minimum Spanning Tree
 
    Flow/Matching
 
        Graph Matching
 
            Bipartite Matching
 
            Hopcroft–Karp Bipartite Matching
 
            Weighted Bipartite Matching/Hungarian Algorithm
 
        Flow
 
            Max Flow/Min Cut
 
            Min Cost Max Flow
 
DFS-like
 
    Backtracking with Pruning/Branch and Bound
 
    Basic Recursion
 
    IDA* Search
 
    Parsing/Grammar
 
    Breadth First Search/Depth First Search
 
    Advanced Search Techniques
 
        Binary Search/Bisection
 
        Ternary Search
 
Geometry
 
    Basic Geometry
 
    Computational Geometry
 
    Convex Hull
 
    Pick‘s Theorem
 
Game Theory
 
    Green Hackenbush/Colon Principle/Fusion Principle
 
    Nim
 
    Sprague-Grundy Number
 
Matrix
 
    Gaussian Elimination
 
    Matrix Exponentiation
 
Data Structures
 
    Basic Data Structures
 
    Binary Indexed Tree
 
    Binary Search Tree
 
    Hashing
 
    Orthogonal Range Search
 
    Range Minimum Query/Lowest Common Ancestor
 
    Segment Tree/Interval Tree
 
    Trie Tree
 
    Sorting
 
    Disjoint Set
 
String
 
    Aho Corasick
 
    Knuth-Morris-Pratt
 
    Suffix Array/Suffix Tree
 
Math
 
    Basic Math
 
    Big Integer Arithmetic
 
    Number Theory
 
        Chinese Remainder Theorem
 
        Extended Euclid
 
        Inclusion/Exclusion
 
        Modular Arithmetic
 
    Combinatorics
 
        Group Theory/Burnside‘s lemma
 
        Counting
 
    Probability/Expected Value
 
Others
 
    Tricky
 
    Hardest
 
    Unusual
 
    Brute Force
 
    Implementation
 
    Constructive Algorithms
 
    Two Pointer
 
    Bitmask
 
    Beginner
 
    Discrete Logarithm/Shank‘s Baby-step Giant-step Algorithm
 
    Greedy
 
    Divide and Conquer
 
Dynamic Programming
                  Tag it!

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

题目大意:有n个人要回到x上的某个聚集点,问所有人都回到该点的最短时间。解题思路:利用三分,求出x点坐标,最后求出最远的点到该点的距离。
#include<bits/stdc++.h>
using namespace std;
struct Cor{
    double x,y;
}cor[55000];
#define mid (L+R)/2.0
#define mid_L (mid+L)/2.0
const double eps=1e-10;
const double INF=1e9;
int n;
double dis(Cor a,Cor b){
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
double calcu(double tx){
    double ret=-INF;
    Cor tmp_;
    tmp_.x=tx,tmp_.y=0;
    for(int i=0;i<n;i++){
        if(ret<dis(cor[i],tmp_)){
            ret=dis(cor[i],tmp_);
        }
    }
    return sqrt(ret);
}
double three_div(double L,double R){
    while(R-L>eps){
        if(calcu(mid)>calcu(mid_L)){
            R=mid;
        }else{
            L=mid_L;
        }
    }
    return mid;
}
int main(){
    while(scanf("%d",&n)!=EOF&&n){
        for(int i=0;i<n;i++){
            scanf("%lf%lf",&cor[i].x,&cor[i].y);
        }
        double ans_x,ans_d;
        ans_x= three_div(-200000.0,200000.0);
        ans_d=calcu(ans_x);
        printf("%.9lf %.9lf\n",ans_x,ans_d);
    }
    return 0;
}

  

时间: 2024-12-19 19:15:03

BNU 4260 ——Trick or Treat——————【三分求抛物线顶点】的相关文章

BNU 4260 Trick or Treat &amp;&amp; ZOJ 3386 (三分查找)

[题目链接]click here~~ [题目大意]求x轴上一点到各点的最大值中的最小值 点到线段距离  [解题思路]三分查找 三分查找初学可以参考这篇博客分析:三分查找,写的很详细了,其实跟类似于二分查找,理解了如何构造,代码不难实现 方法1: #include <bits/stdc++.h> using namespace std; const double eps=1e-7; const double inf=0x3f3f3f3f; const int N=55000; int n; st

zoj 3386 Trick or Treat 三分 求最大值的 最小值

题目来源: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3963 题意:  给定 N 个不同的点, 求在x轴上的 一点,  使 这点到N个点的 距离 最大 的 最小值. f(x) =  max(i){ (xi - x) ^2 + yi ^2 } 求 x  使  min(f(x)) , f(x)为凹函数   ,  采用三分的形式 代码如下: const double EPS = 1e-10 ; const int Max_N

hihoCoder #1142 : 三分求极值

#1142 : 三分·三分求极值 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 这一次我们就简单一点了,题目在此: 在直角坐标系中有一条抛物线y=ax^2+bx+c和一个点P(x,y),求点P到抛物线的最短距离d. 提示:三分法 输入 第1行:5个整数a,b,c,x,y.前三个数构成抛物线的参数,后两个数x,y表示P点坐标.-200≤a,b,c,x,y≤200 输出 第1行:1个实数d,保留3位小数(四舍五入) 样例输入 2 8 2 -2 6 样例输出 2.437

[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轴上从左到最优点,到右, 花费的时间 先降低后升高,那么

三分&#183;三分求极值 算法讲解和题目

题目: #1142 : 三分·三分求极值 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 这一次我们就简单一点了,题目在此: 在直角坐标系中有一条抛物线y=ax^2+bx+c和一个点P(x,y),求点P到抛物线的最短距离d. 提示:三分法 输入 第1行:5个整数a,b,c,x,y.前三个数构成抛物线的参数,后两个数x,y表示P点坐标.-200≤a,b,c,x,y≤200 输出 第1行:1个实数d,保留3位小数(四舍五入) 样例输入 2 8 2 -2 6 样例输出 2

#1142 : 三分&#183;三分求极值 ( 三分极值 )

#1142 : 三分·三分求极值 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 这一次我们就简单一点了,题目在此: [week40_1.PNG] 在直角坐标系中有一条抛物线y=ax^2+bx+c和一个点P(x,y),求点P到抛物线的最短距离d. 提示:三分法 输入 第1行:5个整数a,b,c,x,y.前三个数构成抛物线的参数,后两个数x,y表示P点坐标.-200≤a,b,c,x,y≤200 输出 第1行:1个实数d,保留3位小数(四舍五入) 样例输入 2 8 2

三分&#183;三分求极值

三分求极值 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 这一次我们就简单一点了,题目在此: 在直角坐标系中有一条抛物线y=ax^2+bx+c和一个点P(x,y),求点P到抛物线的最短距离d. 输入 第1行:5个整数a,b,c,x,y.前三个数构成抛物线的参数,后两个数x,y表示P点坐标.-200≤a,b,c,x,y≤200 输出 第1行:1个实数d,保留3位小数(四舍五入) 样例输入 2 8 2 -2 6 样例输出 2.437 #include <iostrea

hihocoder 1142 三分求极值【三分算法 模板应用】

#1142 : 三分·三分求极值 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 这一次我们就简单一点了,题目在此: 在直角坐标系中有一条抛物线y=ax^2+bx+c和一个点P(x,y),求点P到抛物线的最短距离d. 提示:三分法 输入 第1行:5个整数a,b,c,x,y.前三个数构成抛物线的参数,后两个数x,y表示P点坐标.-200≤a,b,c,x,y≤200 输出 第1行:1个实数d,保留3位小数(四舍五入) 样例输入 2 8 2 -2 6 样例输出 2.437

HLJU 1221: 高考签到题 (三分求极值)

1221: 高考签到题 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 9  Solved: 4 [Submit][Status][Web Board] Description 在直角坐标系中有一条抛物线y=ax^2+bx+c和一个点P(x,y),求点P到抛物线的最短距离d. Input 多组数据. 5个整数a,b,c,x,y.前三个数构成抛物线的参数,后两个数x,y表示P点坐标.-200≤a,b,c,x,y≤200 Output 1个实数d,保留