2018ACM-ICPC南京现场赛D题-Country Meow

Problem D. Country Meow

Input file: standard input

Output file: standard output

In the 24th century, there is a country somewhere in the universe, namely Country Meow. Due to advanced technology, people can easily travel in the 3-dimensional space.

There are N cities in Country Meow. The i-th city is located at (xi, yi, zi) in Cartesian coordinate.

Due to the increasing threat from Country Woof, the president decided to build a new combatant command, so that troops in different cities can easily communicate. Hence, the Euclidean distance between the combatant command and any city should be minimized.

Your task is to calculate the minimum Euclidean distance between the combatant command and the farthest city.

Input

The first line contains an integer N (1 ≤ N ≤ 100).

The following N lines describe the i-th city located.Each line contains three integers xi, yi, zi(−100000 ≤ xi, yi, zi ≤ 100000).

Output

Print a real number — the minimum Euclidean distance between the combatant command and the farthest city. Your answer is considered correct if its absolute or relative error does not exceed 10−3. Formally, let your answer be a, and the jury’s answer be b. Your answer is considered correct if |a−b| max(1,|b|) ≤ 10−3.

standard input

3

0 0 0

3 0 0

0 4 0

4

0 0 0

1 0 0

0 1 0

0 0 1

standard output

2.500000590252103

0.816496631812619

思路:

题意是最小球覆盖,一定要读懂题。

好像是计算几何板子题,不过三个三分也是可以过的,模拟退火玄学算法不清楚。

AC_CODE:

#include <bits/stdc++.h>
#define o2(x) (x)*(x)
using namespace std;
typedef long long LL;
const int MXN = 1e5 + 5;
int n;
int x[MXN], y[MXN], z[MXN];
double len(double X, double Y, double Z, int i) {
return o2(X-x[i])+o2(Y-y[i])+o2(Z-z[i]);
}
double exe3(double X, double Y, double Z) {
double ans = 0;
for(int i = 1; i <= n; ++i) ans = max(ans, len(X,Y,Z,i));
return ans;
}
double exe2(double X, double Y) {
double l = -1e6, r = 1e6, midl, midr, ans;
for(int i = 0; i < 70; ++i) {
midl = (l+r)/2;
midr = (midl+r)/2;
if(exe3(X, Y, midl) <= exe3(X, Y, midr)) {
r = midr, ans = midl;
}else {
l = midl, ans = midr;
}
}
return exe3(X, Y, ans);
}
double exe1(double X) {
double l = -1e6, r = 1e6, midl, midr, ans;
for(int i = 0; i < 70; ++i) {
midl = (l+r)/2;
midr = (midl+r)/2;
if(exe2(X, midl) <= exe2(X, midr)) {
r = midr, ans = midl;
}else {
l = midl, ans = midr;
}
}
return exe2(X, ans);
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d%d%d", &x[i], &y[i], &z[i]);
double l = -1e6, r = 1e6, midl, midr, ans;
for(int i = 0; i < 70; ++i) {
midl = (l+r)/2;
midr = (midl+r)/2;
if(exe1(midl) <= exe1(midr)) {
r = midr, ans = midl;
}else {
l = midl, ans = midr;
}
}
double tmp = exe1(ans);
printf("%.9f\n", sqrt(tmp));
return 0;
}

Gym101981D - 2018ACM-ICPC南京现场赛D题 Country Meow的更多相关文章

  1. 2018ACM/ICPC 青岛现场赛 E题 Plants vs. Zombies

    题意: 你的房子在0点,1,2,3,...,n(n<=1e5)点每个点都有一颗高度为0的花,浇一次水花会长a[i]. 你有一个机器人刚开始在你家,最多走m步,每一步只能往前走或者往后走,每走到一 ...

  2. hdu 4435 第37届ACM/ICPC天津现场赛E题

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题目:给出N个城市,从1开始需要遍历所有点,选择一 ...

  3. 2013 ACM/ICPC 南京网络赛F题

    题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...

  4. 2013 ACM/ICPC 长沙现场赛 A题 - Alice's Print Service (ZOJ 3726)

    Alice's Print Service Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is providing print ser ...

  5. 2013 ACM/ICPC 长沙现场赛 C题 - Collision (ZOJ 3728)

    Collision Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge There's a round medal ...

  6. hdu 4432 第37届ACM/ICPC天津现场赛B题

    题目大意就是找出n的约数,然后把约数在m进制下展开,各个数位的每一位平方求和,然后按m进制输出. 模拟即可 #include<cstdio> #include<iostream> ...

  7. 2019 ICPC南京网络赛 F题 Greedy Sequence(贪心+递推)

    计蒜客题目链接:https://nanti.jisuanke.com/t/41303 题目:给你一个序列a,你可以从其中选取元素,构建n个串,每个串的长度为n,构造的si串要满足以下条件, 1. si ...

  8. 2013杭州现场赛B题-Rabbit Kingdom

    杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...

  9. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

随机推荐

  1. [人物存档]【AI少女】【捏脸数据】朴素风格

    点击下载(城通网盘):AISChaF_20191115113752642.png 点击下载(城通网盘):AISChaF_20191111232359711.png

  2. c++之初始化列表

    #include<iostream> using namespace std; class Person{ public: int m_a; int m_b; int m_c; Perso ...

  3. Delphi 消息函数 SendMessage函数

    Delphi中SendMessage使用说明 SendMessage基础知识 函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.而函数Po ...

  4. Shiro学习(13)RememberMe

    Shiro提供了记住我(RememberMe)的功能,比如访问如淘宝等一些网站时,关闭了浏览器下次再打开时还是能记住你是谁,下次访问时无需再登录即可访问,基本流程如下: 1.首先在登录页面选中Reme ...

  5. NOIp2018集训test-10-23

    上午考了一套sb题,但是没有人AK.李巨290虐场. 下午又考了一套sb题,李巨AK虐场.%%% T1 % 中国剩余定理好像做不了啊,我一直在想如何用CRT做,然后就GG了. 然而正解是bike当初说 ...

  6. Android Runnable 运行在那个线程

    Runnable 并不一定是新开一个线程,比如下面的调用方法就是运行在UI主线程中的: Handler mHandler=new Handler(); mHandler.post(new Runnab ...

  7. CF D. Walking Between Houses (贪心)

    题意: 现在有n个房子排成一列,编号为1~n,起初你在第1个房子里,现在你要进行k次移动,每次移动一都可以从一个房子i移动到另外一个其他的房子j里(i != j),移动的距离为|j - i|.问你进过 ...

  8. 如何加大jvm的内存和tomcat的内存

    如何扩大jvm的内存和tomcat的内存,如何让项目没有用的值得到及时的回收和清理,java项目 最佳答案   修改 tomcat 的内存方式:修改 catalina.bat在set JAVA_OPT ...

  9. JAVA调用R脚本 windwos路径下

    RConnection c = new RConnection();// REXP x = c.eval("source('D:\\\\jiaoben\\\\RJava_test.R',en ...

  10. uoj#244. 【UER #7】短路

    题目 orz myy 这个矩形对称的性质非常优美,所以我们只需要考虑一个\(\frac{1}{4}\)的矩阵,即一个倒三角形 现在我们要求的是从\((1,1)\)到三角形对边上每个点的最短路,不难发现 ...