题目大意:

给定一堆点,找到一个点的位置使这个点到所有点中的最小距离最大

这里数据范围很小,精度要求也不高,我们这里可以利用模拟退火的方法,随机找到下一个点,如果下一个点比当前点优秀就更新当前点

参考:http://www.cnblogs.com/heaad/archive/2010/12/20/1911614.html

http://wenku.baidu.com/view/0c6b5df5f61fb7360b4c65a9.html

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <climits>
#include <cmath>
#include <queue>
#include <cstdlib>
#include <ctime>
using namespace std;
#define random(x) ((rand()%x)+1)
#define N 1005
#define ll long long
#define eps 1e-4
const double PI = acos(-1.0);
const int INF = INT_MAX;
const int P = ;
const int L = ; double x,y;
int n;
double dist[N]; struct Point{
double x,y;
Point(double x= , double y=):x(x),y(y){}
}p[N] , tmp[N]; double dis(Point a , Point b)
{
double x = a.x-b.x , y = a.y - b.y;
return sqrt(x*x+y*y);
} double min_dis(Point t)
{
double minn = 1e20;
for(int i= ; i<n ; i++) minn=min(minn , dis(t , p[i]));
return minn;
} bool ok(Point t)
{
return t.x>= && t.x<=x && t.y>= && t.y<=y;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("a.in" , "r" , stdin);
#endif // ONLINE_JUDGE
srand(time());
int T;
scanf("%d" , &T);
while(T--)
{
Point ans;
double ret=; scanf("%lf%lf%d" , &x , &y , &n);
for(int i= ; i<n ; i++){
scanf("%lf%lf" , &p[i].x , &p[i].y);
} for(int i= ; i<P ; i++){
tmp[i].x = random()/1000.0*x;
tmp[i].y = random()/1000.0*y;
dist[i] = min_dis(tmp[i]);
}
double step = sqrt(x*x+y*y)/;
while(step>eps){ for(int i= ; i<P ; i++){
Point cur;
for(int j= ; j<L ; j++){
double ang = random()/1000.0**PI;
cur.x = tmp[i].x+cos(ang)*step;
cur.y = tmp[i].y+sin(ang)*step;
if(!ok(cur)) continue;
double val = min_dis(cur);
if(val>dist[i]){
tmp[i]=cur;
dist[i] = val;
}
}
}
step *= 0.85;
} for(int i= ; i<P ; i++){
if(dist[i]>ret){
ret = dist[i];
ans = tmp[i];
}
}
printf("The safest point is (%.1f, %.1f).\n" , ans.x , ans.y);
}
return ;
}

POJ 1379 (随机算法)模拟退火的更多相关文章

  1. POJ.1379.Run Away(模拟退火)

    题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...

  2. poj 1379 Run Away 模拟退火 难度:1

    Run Away Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6482   Accepted: 1993 Descript ...

  3. POJ 3318:Matrix Multiplication(随机算法)

    http://poj.org/problem?id=3318 题意:问A和B两个矩阵相乘能否等于C. 思路:题目明确说出(n^3)的算法不能过,但是通过各种常数优化还是能过的. 这里的随机算法指的是随 ...

  4. POJ 3318 Matrix Multiplication(随机算法)

    题目链接 随机算法使劲水...srand((unsigned)time(0))比srand(NULL)靠谱很多,可能是更加随机. #include <cstdio> #include &l ...

  5. poj 2069 Super Star —— 模拟退火

    题目:http://poj.org/problem?id=2069 仍是随机地模拟退火,然而却WA了: 看看网上的题解,都是另一种做法——向距离最远的点靠近: 于是也改成那样,竟然真的A了...感觉这 ...

  6. 随机算法 - Miller_Rabin pollard_rho

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  7. 微信红包中使用的技术:AA收款+随机算法

    除夕夜你领到红包了吗?有的说“我领了好几K!”“我领了几W!” 土豪何其多,苦逼也不少!有的说“我出来工作了,没压岁钱了,还要发红包”.那您有去抢微信红包吗?微信群中抢“新年红包”春节爆红.618微信 ...

  8. 抽奖随机算法的技术探讨与C#实现

    一.模拟客户需求 1.1 客户A需求:要求每次都按照下图的概率随机,数量不限,每个用户只能抽一次,抽奖结果的分布与抽奖概率近似. 1.2 客户B需求:固定奖项10个,抽奖次数不限,每个用户只能抽一次, ...

  9. hdu 4712 (随机算法)

    第一次听说随机算法,在给的n组数据间随机取两个组比较,当随机次数达到一定量时,答案就出来了. #include<stdio.h> #include<stdlib.h> #inc ...

  10. 权重随机算法的java实现

    一.概述 平时,经常会遇到权重随机算法,从不同权重的N个元素中随机选择一个,并使得总体选择结果是按照权重分布的.如广告投放.负载均衡等. 如有4个元素A.B.C.D,权重分别为1.2.3.4,随机结果 ...

随机推荐

  1. Ajax深入理解

    Ajax  Asynchronous JavaScript and XML 异步的JavaScript和XML ajax通过与后台服务器进行少量的数据交换,ajax可以使页面实现异步更新,即不需要重新 ...

  2. HV000184: ParameterMessageInterpolator has been chosen, EL interpolation will not be supported问题解决

    今天创建springboot项目的时候添加完依赖启动出现了这个错误 -- :: --- [ main] o.h.v.m.ParameterMessageInterpolator : HV000184: ...

  3. 使用laravel的Command实现搜索引擎索引和模板的建立

    创建command,初始化es 创建成功后,可通过php artisan 查看到 php artisan make:command ESInit 安装guzzle composer require g ...

  4. layer设置弹出全屏

    //弹出即全屏 var index = layer.open({ type: , content: 'http://www.layui.com', area: ['300px', '195px'], ...

  5. 8.2.6 PEB —— PEB结构值不正确的问题

    书中作者使用 dt _PEB xxxxxx 命令来查看当前进程的PEB结构. 实际操作后PEB结构显示的成员值: 作为进程链表的LDR结构居然没有值,这显然是不正常的,地址也没有输错,问题到底出在哪里 ...

  6. (一)VMware Harbor 简介

    (一)Harbor简介 Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全.标识和管理等,扩展了开源Docker Distribu ...

  7. pagehelper 分页

    分页jar包: <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pa ...

  8. linux下C的建立、编译和运行 gcc (附上Windows下visual c++的用法)

    2019/6/24 1. 环境:window10下安装了MobaXterm,这里申请了阿里云的服务账号,可以直接使用linux系统,避免安装虚拟机等. 2. 判断linux下是否有GCC编译工具(我们 ...

  9. 线性判别分析(LDA)

    降维的作用: 高维数据特征个数多,特征样本多,维度也很大,计算量就会很大,调参和最后评估任务时,计算量非常大,导致效率低. 高位数据特征特别多,有的特征很重要,有的特征不重要,可以通过降维保留最好.最 ...

  10. JS常用字符串处理方法应用总结

    这篇文章主要总结了JS常用字符串的处理方法,需要的朋友可以参考下   1.indexOf()方法,从前往后查找字符串位置,大小写敏感,从0开始计数.同理,lastIndexOf() 方法从后往前,两个 ...