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

题意

三维空间有\(n\)个点,找到另外一个点,离所有点的最大距离最小。求这个距离。

题解

\(1\)、最小球覆盖,要找的点为球心。

\(2\)、模拟退火。

还是补一下模拟退火的介绍吧。

模拟退火有一个初始温度,温度越高,接受较差的解的可能性就越大。每次走完后,都会降低温度,使得接受较差解的可能性变小。在走的过程中,更新最优解的值。

对这个题目来说,从空间中某一个点出发,如果每次都找离当前点最远的点,往那个点的方向走,大概率可以使结果变得更优。

随便设了个温度下降速率为\(0.97\),一遍就AC了。参数都不用调。

#include <bits/stdc++.h>

#define FOPI freopen("in.txt", "r", stdin)
#define FOPO freopen("out.txt", "w", stdout)

using namespace std;
typedef long long LL;
const int maxn = 100 + 5;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const double start_T = 1000;

struct Point
{
    double x, y, z;
    Point() {}
    Point(int _x, int _y, int _z):x(_x), y(_y), z(_z) {}
}a[maxn];

double dist(Point a, Point b)
{
    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));
}

int n;
double SA()
{
    Point p = Point(0,0,0);
    int s = 0;
    double ans = inf, rate = 0.97, T = start_T;
    while(T > eps)
    {
        for (int i = 1; i <= n; i++)
            if(dist(p, a[i]) > dist(p, a[s])) s = i;
        double d = dist(p, a[s]);
        ans = min(ans, d);
        p.x += (a[s].x - p.x) * T / start_T;
        p.y += (a[s].y - p.y) * T / start_T;
        p.z += (a[s].z - p.z) * T / start_T;
        T *= rate;
    }
    return ans;
}

int main()
{
//    FOPI;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lf%lf%lf", &a[i].x, &a[i].y, &a[i].z);
    double ans = SA();
    printf("%.8f\n", ans);
}

原文地址:https://www.cnblogs.com/ruthank/p/10910513.html

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

Gym - 101981D Country Meow(模拟退火)的相关文章

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

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

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 #in

Gym 101246D Fire in the Country(dfs求SG函数)

http://codeforces.com/gym/101246/problem/D 题意: 给定一个无向有环图,大火从1点开始,每个时间点与它相邻的点也将会着火,现在有两个人轮流操作机器人,机器人从1点出发,每个人每次选择一个点走,谁最后被火烧了谁就输了. 思路: 博弈题. 我们先预处理求出每个点着火的时间点,然后根据时间点重建新图,也就是重新建一个有向无环图,原来图中相连的并且时间点相差1的相连,由时间低的连向时间高的. 接下来我们在新图上求每个点的SG值,SG值为0的点就是叶子结点,这样父

Codeforces Gym - 101147J Whistle&#39;s New Car

Discription Statements Whistle has bought a new car, which has an infinite fuel tank capacity. He discovered an irregular country since it has n cities and there are exactly n?-?1roads between them, of course, all cities are connected. He is so much

CodeForces Gym 100935D Enormous Carpet 快速幂取模

Enormous Carpet Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Gym 100935D Description standard input/outputStatements Ameer is an upcoming and pretty talented problem solver who loves to solve problems using computers.

poj-2420 A Star not a Tree?(模拟退火算法)

题目链接: A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5219   Accepted: 2491 Description Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10base2 (coaxial) cables that allo

POJ 3087 Shuffle&#39;m Up(模拟退火)

Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several

B - Average Gym - 101161B 组合数学

http://codeforces.com/gym/101161/attachments 今天被卡常了,其实是自己对组合数技巧研究的不够. 如果是n, m <= 1e5的,然后取模是质数,那么可以用费马小定理. 如果n, m都比较小,那么其实是直接杨辉三角.不用逆元那些. 这题的思路是,枚举每一一个ave,然后总和就是n * ave 相当于方程  x1 + x2 + .... + xn = n * ave中,在0 <= x[i] <= full的情况下,不同解的个数中,使得x[i] ==

Codeforces Gym 100269 Dwarf Tower (最短路)

题目连接: http://codeforces.com/gym/100269/attachments Description Little Vasya is playing a new game named "Dwarf Tower". In this game there are n different items,which you can put on your dwarf character. Items are numbered from 1 to n. Vasya want