Gym101981D - 2018ACM-ICPC南京现场赛D题 Country Meow
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的更多相关文章
- 2018ACM/ICPC 青岛现场赛 E题 Plants vs. Zombies
题意: 你的房子在0点,1,2,3,...,n(n<=1e5)点每个点都有一颗高度为0的花,浇一次水花会长a[i]. 你有一个机器人刚开始在你家,最多走m步,每一步只能往前走或者往后走,每走到一 ...
- hdu 4435 第37届ACM/ICPC天津现场赛E题
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题目:给出N个城市,从1开始需要遍历所有点,选择一 ...
- 2013 ACM/ICPC 南京网络赛F题
题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...
- 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 ...
- 2013 ACM/ICPC 长沙现场赛 C题 - Collision (ZOJ 3728)
Collision Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge There's a round medal ...
- hdu 4432 第37届ACM/ICPC天津现场赛B题
题目大意就是找出n的约数,然后把约数在m进制下展开,各个数位的每一位平方求和,然后按m进制输出. 模拟即可 #include<cstdio> #include<iostream> ...
- 2019 ICPC南京网络赛 F题 Greedy Sequence(贪心+递推)
计蒜客题目链接:https://nanti.jisuanke.com/t/41303 题目:给你一个序列a,你可以从其中选取元素,构建n个串,每个串的长度为n,构造的si串要满足以下条件, 1. si ...
- 2013杭州现场赛B题-Rabbit Kingdom
杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...
- 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 ...
随机推荐
- Java中的Set集合以及HashSet
Set集合: Set继承自Collection,所以没有什么特别的方法. 需要注意的是,Set集合不包含重复元素,我们重点了解Set集合如何保证不包含多余元素. HashSet: HashSet如何保 ...
- WPF ItemControl的源与选择项问题
具体场景: datagrid的行中有个combox 每个行是一个实例A 每个行中的SelectedItem是实例A的一个属性B 我希望实现datagrid的复制Command,具体做法是A序列化反序列 ...
- cmake build
{ //cmake CMakeLists.txt -G "Visual Studio 15 2017" }
- Java获取CPU占用率
原文链接:https://www.jianshu.com/p/015cc4805e29 最近做一个Java性能统计的问题,需要统计当前进程占用CPU的情况,最开始使用Java MxBean来获取 Op ...
- Codeforces 1176B - Merge it!
题目链接:http://codeforces.com/problemset/problem/1176/B 题意:给定序列,任意俩个元素可以相加成一个元素,求序列元素能被3整除的最大数量. 思路: 对于 ...
- Python爬虫工程师必学APP数据抓取实战✍✍✍
Python爬虫工程师必学APP数据抓取实战 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程本身没问题,大 ...
- 判断页面是否在iframe中,
//判断页面是否在iframe中,是的话就跳出iframe框,多用于登录页 ,将此段代码放到要做判断的页面上即可 if (window != top) { top.location.href = l ...
- .Net中Task使用来提高代码执行效率
技术不断更新迭代,更高效的执行效率越来越被重视,所以对Task的使用进行了简单使用做了整理与大家分享. .Net 中有了Task后使多线程编程更简单使用和操作,下面粘上代码进行简单说明: /// &l ...
- js实现各种复制功能
引用: <script src="https://clipboardjs.com//dist/clipboard.min.js"></script> 示例1 ...
- ARM 寄存器 和 工作模式了解
一. ARM 工作模式 1. ARM7,ARM9,ARM11,处理器有 7 种工作模式:Cortex-A 多了一个监视模式(Monitor) 2. 用户模式:非特权模式,大部分任务执行在这种模式 ...