Country Meow

Country Meow

和这基本一样 https://www.cnblogs.com/Fighting-sh/p/9809518.html

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<string>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<vector>
 9 #include<map>
10 using namespace std;
11
12 struct Point{
13     double x,y,z;
14 }p[105];
15
16 double dist(Point a,Point b){
17     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
18 }
19
20 double ac(int n){
21     double ans=1e9;
22     Point tmp;
23     tmp.x=tmp.y=tmp.z=0;;
24     int s=1;
25     double step=1000;
26     double esp=0.0000001;
27     while(step>esp){
28         for(int i=1;i<=n;i++){
29             if(dist(tmp,p[s])<dist(tmp,p[i])) s=i;
30         }
31         double Dist=dist(tmp,p[s]);
32         ans=min(ans,Dist);
33         tmp.x+=(p[s].x-tmp.x)/Dist*step;
34         tmp.y+=(p[s].y-tmp.y)/Dist*step;
35         tmp.z+=(p[s].z-tmp.z)/Dist*step;
36         step*=0.999;
37     }
38     return ans;
39 }
40
41 int main(){
42     int n;
43     while(~scanf("%d",&n)){
44         if(!n) break;
45         for(int i=1;i<=n;i++){
46             scanf("%lf %lf %lf",&p[i].x,&p[i].y,&p[i].z);
47         }
48         double ans=ac(n);
49         printf("%.5f\n",ans);
50     }
51 }

原文地址:https://www.cnblogs.com/Fighting-sh/p/10004196.html

时间: 2024-08-02 17:33:16

Country Meow的相关文章

D.Country Meow 最小球覆盖 三分套三分套三分 &amp;&amp; 模拟退火

// 2019.10.3 // 练习题:2018 ICPC 南京现场赛 D Country Meow 题目大意 给定空间内 N 个点,求某个点到 N 个点的距离最大值的最小值. ? 思路 非常裸的最小球覆盖问题啊,即找到半径最小的球包含全部的点. 在最小圆覆盖问题上,可以使用随机增量法,这里没有四点确定球心的公式,所以板子失效了. 最小圆覆盖可以用三分套三分,这里空间有三维,假装证明得到在任意一维上都满足凸函数特性,那么再套一层维度三分就OK了. ? AC代码 三分套三分套三分写法,复杂度O(n

Gym - 101981D Country Meow(模拟退火)

题意 三维空间有\(n\)个点,找到另外一个点,离所有点的最大距离最小.求这个距离. 题解 \(1\).最小球覆盖,要找的点为球心. \(2\).模拟退火. 还是补一下模拟退火的介绍吧. 模拟退火有一个初始温度,温度越高,接受较差的解的可能性就越大.每次走完后,都会降低温度,使得接受较差解的可能性变小.在走的过程中,更新最优解的值. 对这个题目来说,从空间中某一个点出发,如果每次都找离当前点最远的点,往那个点的方向走,大概率可以使结果变得更优. 随便设了个温度下降速率为\(0.97\),一遍就A

HDU5723 Abandoned country 最小生成树+深搜回溯法

Description An abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since abandoned for a long time, the roads need to be re-built. There are m(m≤1000000) roads to be re-built, the length of each road is wi(wi≤1000000). Guarante

hdu 5723 Abandoned country 最小生成树+子节点统计

Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3006    Accepted Submission(s): 346 Problem Description An abandoned country has n(n≤100000) villages which are numbered from 1

HDU计算机学院大学生程序设计竞赛(2015’12)The Country List

The Country List Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2598    Accepted Submission(s): 615 Problem Description As the 2010 World Expo hosted by Shanghai is coming, CC is very honorable

zoj 3332 Strange Country II

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3332 Description You want to visit a strange country. There are n cities in the country. Cities are numbered from 1 to n. The unique way to trav

ural 1073. Square Country

1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square country. Everything in this country is square also. Thus, the Square Parliament has passed a law about a land. According to the law each citizen of th

URAL 1073 Square Country(DP)

题目链接 题意 :这个人要投资地,每块地都是正方形并且边长都是整数,他希望他要买的地尽量的少碎块.每买一块地要付的钱是边长的平方,而且会得到一个一份证书,给你一个钱数,让你求出能得到的证书个数. 思路 :其实就是求x12+x22+--+Xn2中的最小的n. 1 //1073 2 #include <stdio.h> 3 #include <iostream> 4 #include <math.h> 5 6 using namespace std ; 7 8 int a[

ural1097 Square Country 2

Square Country 2 Time limit: 1.0 secondMemory limit: 64 MB The Square Parliament of the Square country (recall the corresponding problem from the USU 2001 personal contest) has decreed that the National Square Park be created. Of course, the Park sho