poj1379 Run Away

传送门:http://poj.org/problem?id=1379

【题解】

题目大意:求(0,0)->(X,Y)内的一个点,使得这个点到给定的n个点的最小距离最大。

模拟退火

一开始可以先把4个顶点加入。

调调参就过样例了。

然后就过了

# include <math.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + 10;
const int mod = 1e9+7;
const double pi = acos(-1.0);

# define RG register
# define ST static

double X, Y;
int n;
struct pa {
    double x, y;
    double dis;
    pa() {}
    pa(double x, double y, double dis) : x(x), y(y), dis(dis) {}
}a[M];

namespace SA {
    const double eps = 1e-2, DEC = 0.9, ACCEPT_DEC = 0.5;
    const int N = 30, T = 30, RAD = 1000;
    inline double rand01() {
        return rand() % (RAD + 1) / (1.0 * RAD);
    }
    inline double getdist(double x, double y) {
        double ret = 1e18;
        for (int i=1; i<=n; ++i)
            ret = min(ret, (x-a[i].x)*(x-a[i].x)+(y-a[i].y)*(y-a[i].y));
        return ret;
    }
    pa res[N + 5];
    inline pa main() {
        res[1] = pa(0, 0, getdist(0, 0));
        res[2] = pa(X, 0, getdist(X, 0));
        res[3] = pa(0, Y, getdist(0, Y));
        res[4] = pa(X, Y, getdist(X, Y));
        for (int i=5; i<=N; ++i) {
            double x = rand01() * X;
            double y = rand01() * Y;
            res[i] = pa(x, y, getdist(x, y));
        }
        double temper = max(X, Y), accept = 0.6;
        while(temper > eps) {
            for (int i=1; i<=N; ++i) {
                for (int j=1; j<=T; ++j) {
                    double theta = rand01() * 2 * pi;
                    double xx = res[i].x + temper * cos(theta);
                    double yy = res[i].y + temper * sin(theta);
                    if(0 <= xx && xx <= X && 0 <= yy && yy <= Y) {
                        pa t = pa(xx, yy, getdist(xx, yy));
                        if(t.dis > res[i].dis) res[i] = t;
                        else if(rand01() <= accept) res[i] = t;
                    }
                }
            }
            temper *= DEC;
            accept *= ACCEPT_DEC;
        }
        pa ans;
        ans.dis = 0;
        for (int i=1; i<=N; ++i)
            if(res[i].dis > ans.dis) ans = res[i];
        return ans;
    }
}

int main() {
    srand(19260817);
    int T; cin >> T;
    while(T--) {
        cin >> X >> Y >> n;
        for (int i=1; i<=n; ++i) scanf("%lf%lf", &a[i].x, &a[i].y);
        pa ans = SA::main();
        printf("The safest point is (%.1f, %.1f).\n", ans.x, ans.y);
    }

    return 0;
}

时间: 2024-08-11 05:35:03

poj1379 Run Away的相关文章

【模拟退火】poj1379 Run Away

题意:平面上找一个点,使得其到给定的n个点的距离的最小值最大. 模拟退火看这篇:http://www.cnblogs.com/autsky-jadek/p/7524208.html 这题稍有不同之处仅有:多随机几个初始点,以增加正确率. 另:WA了几百遍竟然是因为最后输出了-0.0这样的值…… #include<cstdio> #include<cmath> #include<algorithm> #include<cstdlib> using namesp

【POJ1379】Run Away 模拟退火

#include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/43526827"); } 题意: 给若干个点,现在求一个点,使它到离它最近的点尽量远. 题解: 我写的是模拟退火先玩一会,然后小幅度爬爬山. 种子的采用是20134858 是生日^人的名字首字母hash. 诶可算A了,看来我脸还不是太黑. 代

poj1379+POJ2420+hdu3932(最短距离+费马点+模拟淬火算法)

Run Away Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5632   Accepted: 1729 Description One of the traps we will encounter in the Pyramid is located in the Large Room. A lot of small holes are drilled into the floor. They look complet

docker run常用命令及 解决 ubuntu镜像无法识别 ifconfig ping 命令

docker run -it     docker 前端启动 container容器           -d             后端启动 container容器           -p             固定端口映射            -P             不固定端口映射           --name         给生成的容器起名字docker ps:默认显示正在运行的container       ps -a 显示所有的container容器docker r

Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast

1.事件描述:CentOS7下使用tree命令,发现该命令没有被安装,在安装的过程中发现yum报错 [[email protected] ~]# tree -d bash: tree: 未找到命令... [[email protected] ~]# yum -y install tree 已加载插件:fastestmirror, langpacks Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast

Linux联接vsftpd:500 OOPS: vsftpd: refusing to run with writable root inside chroot ()错误

当我们限定了用户不能跳出其主目录之后,使用该用户登录FTP时往往会遇到这个错误: [html] view plaincopy 500 OOPS: vsftpd: refusing to run with writable root inside chroot () 这个问题发生在最新的这是由于下面的更新造成的: [html] view plaincopy - Add stronger checks for the configuration error of running with a wri

duplicate from active dg 的 run 脚本 sfile 为完整配置可能导致的一些错误

oracle 11g RMAN:Active Database Duplication for standby database 创建dg 命令解读 继上篇如果没有正确配置,理解duplicate from active  dg 的 run 脚本,就会出现以下错误: 1:路径不存在: Oracle instance shut down connected to auxiliary database (not started) RMAN-00571: =======================

Docker run 参考指南

Docker run参考指南 docker运行在一个独立的隔离的进程中. 当用户执行dockerrun,它将启动一个有着独立的文件系统,独立的网络和独立的进程树的进程. 基本的docker run命令的格式: docker run  [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...] [OPTIONS]分为两种: 1.对于用户独占性的设置: 前台.后台运行 容器定义 网络设定 容器在CPU和内存中的运行时间 运行权限和LXC配置 2.在操作者和开发者之间的共享设定,

linux下.run文件的安装与卸载

.run文件的安装很简单,只需要为该文件增加可执行属性,即可执行安装 以 virtualbox 的安装文件 virtualbox-3.1.6-59338-Linux_x86.run为例,只需要输入命令: chmod +x  virtualBox-3.1.6-59338-Linux_x86.run ./virtualbox-3.1.6-59338-Linux_x86.run 即可安装. www.2cto.com 卸载的方法网上说法大至分两种: 一种是说用 sh  virtualbox-3.1.6-