1. 程式人生 > >2018ACM-ICPC南京現場賽D題 Country Meow

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;
}

相關推薦

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 so

2018ACM-icpc北京現場D. Frog and Portal(構造)

題目連結:QAQ     題意:一直小青蛙位於標號為0的荷葉,他要跳到標號為200的荷葉,他每次只能想右跳一格或者兩格,現在有傳送門,如果x號的荷葉上建著傳送門,如果小青蛙到達x位置,就必須傳送到傳送門指定的位置,一個荷葉上只能建一個傳送門的起點。題目中指出如果沒有傳

2018ACM/ICPC南京網路B-The writing on the wall (補

題目連結 題意:求n*m的區域中不含有黑色格子的矩形數量。 這題給了2s的時限,m只給了100,暴力複雜度可以是O(n*m*m),接近1e9,能過,大概1300+ms。。。因為高中的時候懶得學組合數學,導致現在對計數的東西一竅不通,連沒有黑色格子的情況居然都想不清楚Q

ZOJ3822 ACM-ICPC 2014 亞洲區域牡丹江賽區現場DDomination 概率DP

Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headmaster of Marjar University. He is ent

2018ACM-ICPC南京區域【待填】

含【最小球覆蓋】模板。 題面pdf https://codeforc.es/gym/101981/attachments/download/7891/20182019-acmicpc-asia-nanjing-regional-contest-en.pdf A---Adrien and Austin【博

2018ACM-ICPC南京區域M---Mediocre String Problem【exKMP】【Manacher】

比較 回文 題意 連續 三元 wid 第一步 com info 這題就單獨寫個題解吧。想了兩天了,剛剛問了一個大佬思路基本上有了。 題意: 一個串$S$,一個串$T$,在$S$中選一段子串$S[i,j]$,在$T$中選一段前綴$T[1,k]$使得$S[i,j]T[1,k]

2018年ACM-ICPC 南京現場 A.Adrien and Austin

題意 有一堆數量為N的石子,石子編號從1⋯N1\cdots N1⋯N排成一列,兩個人玩遊戲,每次可以取1⋯K1\cdots K1⋯K個連續編號的石子,Adrien先手,如果有誰不能取了則他輸,兩個人為A

ZOJ-4061 Magic Multiplication 2018年青島區域現場D(思維 + 暴力構造)

題目連結:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4061 題目大意:題目定義一個運算子對於數A和數B的運演算法則為 , 表示數A的第 i 位數,表示數B的第 j 位數,現在令字串,這裡的加法為字串連

2017 ACM-ICPC西安現場 JLOL(暴力)

題意:輸入五個長度為100的01串,從每個串中選擇一個是1的位置,任意兩個串中選擇的位置不能相同,一共有多少種情況,答案乘以常數531192758再對1e9+7取模。 如果對五個串都dfs複雜度是10^10穩T,所以對前四個串dfs,最後一個串的貢獻直接加到最終的答案上。

ACM-ICPC 長沙現場 C ZOJ3728(為什麼我A過的數學題都是水T_T)

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge There's a round medal fixed on an ideal smooth table, Fancy is tryi

HDU5575 Discover Water Tank 2015上海現場D (樹形dp,並查集,左偏樹)

題目大意: 有一個1維的長度為N,高度無限的水櫃,現在要用N-1個擋板將其分為N個長度為1的小格,然後向水櫃中注水,水可以低於擋板也可以以溢位去(這樣就要與旁邊格子的水位相同),現在有M次探測,探測i,y,k為查詢第i個格子高度y+0.5處是否有水,k=1表示

ZOJ 3822 Domination 概率DP 2014年ACM_ICPC亞洲區域牡丹江現場D

題目大意: 就是現在有一個N*M的棋盤(1 <= N, M <= 50)每次在上面的空位置隨機選一個放一個棋子, 問使得所有行和所有列上都有棋子放置, 放置的棋子的數目期望 大致思路: 這題同步賽的時候沒感覺, 現在做發現就是一個水題, 當時還是太弱了...

2018ACM-ICPC徐州網路 D Easy Math

求解∑mi=1μ(in)求解∑i=1mμ(in) 記:S(m,n)=∑mi=1μ(in)S(m,n)=∑i=1mμ(in) =μ(n)∑mi=1μ(i)[gcd(i,n)==1]=μ(n)∑i=1mμ(i)[gcd(i,n)==1] =μ(n)∑mi=1μ

2018ACM/ICPC南京站網路C-GDY (補)(暴力模擬)

題目連結 題意:十三種牌1、2、...、13,和撲克牌一樣,不過JQK換成了11、12、13,大小是一樣的,即3<4<5<...<13<1<2。已知n個人,m張牌,初始每個人從1到n按順序各抽五張牌,可能出現牌堆已抓完但是最後一個人手中不

ACM-ICPC 2018 青島賽區現場 D. Magic Multiplication && ZOJ 4061 (思維+構造)

題目連結:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4061 題意:定義一個長度為 n 的序列 a1,a2,..,an 和長度為 m 的序列 b1,b2,..,bm 所構成的新序列 c 為 a1b1,a1b2,....,anbm

2018ACM-ICPC北京網路 A-Saving Tang Monk II

題目連結: Saving Tang Monk II 題目大意: 給你一個n*m的圖,你要從S走到T,每走一步都要花費1的時間,現在有的房間會有不同,’.'代表空房間,走入後不會發生什麼,'B’代表有氧氣瓶的房間,每走入一次就能得到一罐氧氣瓶(但持續呆在裡面不會得到,氧氣瓶的攜帶上限是

2018 ACM-ICPC 亞洲區域北京現場 I

做法:打表找規律 大數是過不了這個題的(但可以用來打表) 先找k的字首,字首對應邊緣數字是哪個 如果第0位是2-9 對應奇數長度的1-8 第0位為1時,第1位為0時對應奇數長度的9,為1-9時對應偶數長度的1-9,剩下的根據奇偶判斷先從頭到尾再從尾到頭跑一編即可 如100會得到909 100234會得

ACM 2018 南京區域 D - Country Meow (最小圓覆蓋/三分)

Gym 101981D 題目大意:        宇宙中有n個城市,需要建一個指揮部,使得指揮部與所有城市之間的距離儘可能小。問指揮部和最遠城市之間的最小歐幾里得距離是多少。 題解:    

2018年 ACM/ICPC亞洲區域 青島賽區現場 F(ZOJ 4063 思維)

DreamGrid, the king of Gridland, is making a knight tournament. There are  knights, numbered from 1 to , participating in the tournamen

2015 ACM/ICPC 北京區域 現場 D—Kejin Game【網路流】

題意: 題意:給一顆有向樹,技能獲得的前提是他的前置技能都獲得了,作為一個玩家,你有特權: 1.直接花費一定數量的錢獲得某個技能。 2.花費一定數量的錢將一個技能的某一個前置關係取消,即將前置技能到該技能的邊消除(不需要獲得前置技能)。 如果正常學習技能的話