模拟退火算法,很久之前就写过一篇文章了。双倍经验题(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. Oracle RAC集群搭建(二)-基础环境配置

    01,创建用户,用户组 [root@rac1 ~]# groupadd -g 501 oinstall [root@rac1 ~]# groupadd -g 502 dba [root@rac1 ~] ...

  2. zabbix 监控 tomcat

    一, 脚本监控文件 #!/bin/bash # @Function # Find out the highest cpu consumed threads of java, and print the ...

  3. Python的静态方法和类成员方法都可以被类或实例访问,两者概念不容易理清,但还是有区别的

    转:http://www.cnblogs.com/2gua/ Python的静态方法和类成员方法都可以被类或实例访问,两者概念不容易理清,但还是有区别的: 1)静态方法无需传入self参数,类成员方法 ...

  4. python移动多个子文件中的文件到一个文件夹

    import os import os.path import shutil def listDir(dirTemp): if None == dirTemp: return global nameL ...

  5. LeetCode 319 ——Bulb Switcher——————【数学技巧】

    319. Bulb Switcher My Submissions QuestionEditorial Solution Total Accepted: 15915 Total Submissions ...

  6. nyoj 104——最大和——————【子矩阵最大和】

    最大和 时间限制:1000 ms  |  内存限制:65535 KB 难度:5   描述 给定一个由整数组成二维矩阵(r*c),现在需要找出它的一个子矩阵,使得这个子矩阵内的所有元素之和最大,并把这个 ...

  7. 利用pandas生成csv文件

    # -*- coding:UTF-8 -*- import json from collections import OrderedDict with open('dns_status.json',' ...

  8. 《Python编程从入门到实践》_第三章_列表简介

    什么是列表呢? 官方说明就是由一些列按特点顺序排列的元素组成.其实可以看出很多个字符串的有序组合吧,里面的内容可以随时的删除,增加,修改. 下面这个就是一个列表,python打印列表的时候会将中括号和 ...

  9. 微信小程序开发踩坑记录

    1.由于小程序wx.request()方法是异步的,在app.js执行ajax后,各分页加载app.js的全局数据时,无法按顺序加载.例: //app.js App({ ajax:function() ...

  10. 数据类型之Nullable

    Nullable 此结构在 .NET Framework 2.0 版中是新增的.