模拟退火算法,很久之前就写过一篇文章了。双倍经验题(POJ 2420)

题意:

在一个矩形区域内,求一个点的距离到所有点的距离最短的那个,最大。

这个题意,很像二分定义,但是毫无思路,也不能暴力枚举,那就模拟退火。

参考著名的ACdream,哈哈,有个共同点,那就是,大部分的代码,都没有做接受准则,这也许是acmer对智能算法的不习惯吧~~~

#include <stdio.h>
#include <math.h>
#include <algorithm> using namespace std; const int maxn = ; int X,Y,M;
int Kase; struct Node {
double x,y;
}nodes[maxn]; int dx[] = {,,-,};
int dy[] = {-,,,}; double dist(Node a,Node b) {
return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} double calc(Node p) {
double ret = 0x3f3f3f3f;
for(int i = ; i < M; i++)
ret = min(ret,dist(p,nodes[i]));
return ret;
} int main()
{
//freopen("in.txt","r",stdin);
scanf("%d",&Kase);
while(Kase--) {
scanf("%d%d%d",&X,&Y,&M); for(int i = ; i < M; i++) scanf("%lf%lf",&nodes[i].x,&nodes[i].y); Node s;
s.x = X/;
s.y = Y/; double t = max(X,Y);
double ansx = X/;
double ansy = Y/;
double ans = calc(s); Node tmp;
tmp.x = ;
tmp.y = ;
double anstmp = calc(tmp);
if(anstmp>ans) {
ans = anstmp;
ansx = ;
ansy = ;
} tmp.x = ;
tmp.y = Y;
anstmp = calc(tmp);
if(anstmp>ans) {
ans = anstmp;
ansx = ;
ansy = Y;
} tmp.x = X;
tmp.y = ;
anstmp = calc(tmp);
if(anstmp>ans) {
ans = anstmp;
ansx = X;
ansy = ;
} tmp.x = X;
tmp.y = Y;
anstmp = calc(tmp);
if(anstmp>ans) {
ans = anstmp;
ansx = X;
ansy = Y;
} while(t>1e-) {
bool flag = true;
while(flag) {
flag = false;
for(int i = ; i < ; i++) {
Node v;
v.x = s.x + dx[i]*t;
v.y = s.y + dy[i]*t;
if(v.x>X||v.y>Y||v.x<||v.y<) continue; double tp = calc(v); if(tp>ans) {
ans = tp;
flag = true;
ansx = v.x;
ansy = v.y;
s = v;
}
}
}
t = t*0.98;
} printf("The safest point is (%.1f, %.1f).\n",ansx,ansy);
}
return ;
}

POJ 1379 模拟退火的更多相关文章

  1. POJ 1379 Run Away 【基础模拟退火】

    题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...

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

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

  3. POJ 1379 (随机算法)模拟退火

    题目大意: 给定一堆点,找到一个点的位置使这个点到所有点中的最小距离最大 这里数据范围很小,精度要求也不高,我们这里可以利用模拟退火的方法,随机找到下一个点,如果下一个点比当前点优秀就更新当前点 参考 ...

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

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

  5. poj 2420(模拟退火)

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6066   Accepted: 285 ...

  6. POJ 1379

    模拟退火算法. 随机MAX个点,然后,退火移动,选取距离所有点中最短中最长者即可.理解和我上一篇一样. #include <iostream> #include <cstdio> ...

  7. BZOJ 1379 模拟退火

    模拟退火的第一题~ //By SiriusRen #include <cmath> #include <cstdio> #include <algorithm> u ...

  8. POJ 1379 Run Away

    题意:有n个陷阱,在X,Y范围内要求出一个点使得这个点到陷阱的最小距离最大. 思路:模拟退火,随机撒入40个点,然后模拟退火随机化移动. (这题poj坑爹,加了srand(time(NULL))不能交 ...

  9. POJ 2069 模拟退火算法

    Super Star Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6422   Accepted: 1591   Spec ...

随机推荐

  1. vm12下Centos6安装mysql5.7

    一.下载mysql的rpm tar文件 文件名称:mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar官方地址:https://dev.mysql.com/get/Down ...

  2. 基于前端js模板替换的多语言方案思考

    最近在做将一个系统多语言化的项目,系统使用的是ASP.NET,直接使用了一种已有的方案:在页面渲染时采用正则表达式替换{XXX:001 确定}格式的标记.但是这个方式增加了服务端的字符串处理,对页面性 ...

  3. 8086键盘输入实验——《x86汇编语言:从实模式到保护模式》读书笔记07

    1.BIOS中断 我们可以为所有中断类型自定义中断处理过程,包括内部中断.硬件中断和软中断. BIOS中断,又称BIOS功能调用,主要是为了方便地使用最基本的硬件访问功能.通常,为了区分针对同一硬件的 ...

  4. BJFU 1549 ——Candy——————【想法题】

    Candy 时间限制(C/C++):1000MS/3000MS          运行内存限制:65536KByte总提交:40            测试通过:20 描述 There are N c ...

  5. 2、按钮:Buttons

    /* --- page1.html ---*/ <ion-content padding class="page1"> <h1>基本用法,实体框</h ...

  6. js【jquery】-事件

    1.event对象 在IE.chrome中它是全局变量 与事件相关的信息会保存在event对象中,只有在事件发生的过程中,event才有信息 在其他浏览器中: 通过事件函数的第一个参数传入的 even ...

  7. javascript方法重载惹的祸

    先贴出代码,看看执行结果会是什么? function ShowMsg() { //函数1 this.sure = function () { alert("ok"); }; //函 ...

  8. 序列化json和protobuf大小比较

    使用protobuf序列化为二进制和json序列化字符串大小比较 代码demo package com.gxf.demo; import java.io.*; public class Ptotobu ...

  9. 02_SimpleTrigger

    [SimpleTrigger的构造方法] SimpleTrigger(String name,String group); //指定Trigger的所属组 和 名称 SimpleTrigger(Str ...

  10. ArcGIS Enterprise 10.5.1 静默安装部署记录(Centos 7.2 minimal)- 6、总结

    安装小结 安装完成后,首先我们需要将Datastore托管给Server,再将Server托管给Portal以此来完成整个单机版Enterprise 部署流程.为了测试流程是否正确,我们可以采用上传一 ...