poj1379 模拟退火
题意:和上题一样。。。就是把最小值换成了最大值。。
ref:http://www.cppblog.com/RyanWang/archive/2010/01/21/106112.html
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std; #define eps 1e-3
#define pi acos(-1.0)
#define POI 15 //独立跑POI次,找最值 tp[1..POI]是随机的初值
#define RUN 40 //迭代次数,本题中即点(tx,ty)向RUN个方向发散
#define INF 99999.999
int X,Y,N,T;
double ans;
int ansi;
struct
{
double x,y;
}tp[],hol[];
double sol[]; double dist(double x1,double y1,double x2,double y2)
{
return(sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
} double dis(double x,double y)
{
double tmp=INF;
for(int i=;i<=N;i++)
{
double tx=hol[i].x,ty=hol[i].y;
tmp=min(tmp,dist(tx,ty,x,y));
}
return tmp;
} void sa()
{
for(int i=;i<=POI;i++)
{
tp[i].x=(rand()%+)/1000.0*X;
tp[i].y=(rand()%+)/1000.0*Y;
sol[i]=dis(tp[i].x,tp[i].y);
//printf("%.1f~%.1f=%.1f\n",tp[i].x,tp[i].y,sol[i]);
} double step=1.0*max(X,Y)/sqrt(1.0*N);
while(step>eps)
{
for(int i=;i<=POI;i++)
{
double kx=tp[i].x,ky=tp[i].y;
double tx=kx,ty=ky;
for(int j=;j<RUN;j++)
{
double angle=(rand()%+)/1000.0**pi;
kx=tx+cos(angle)*step;
ky=ty+sin(angle)*step;
if((kx>X)||(ky>Y)||(kx<)||(ky<)) continue;
double tmp=dis(kx,ky);
if(tmp>sol[i])
{
tp[i].x=kx; tp[i].y=ky;
sol[i]=tmp;
}
}
}
step*=0.80;
}
} int main()
{
srand(time(NULL));
cin>>T;
//cout<<T<<endl;
while(T--)
{
cin>>X>>Y>>N;
for(int i=;i<=N;i++)
cin>>hol[i].x>>hol[i].y; sa(); ans=0.000;
for(int i=;i<=POI;i++)
{
//printf("AA: %.1f~%.1f=%.1f\n",tp[i].x,tp[i].y,sol[i]);
if(sol[i]>ans)
{
ans=sol[i];
ansi=i;
}
}
printf("The safest point is (%.1f, %.1f).\n",tp[ansi].x,tp[ansi].y);
//printf("%.1lf\n",ans);
}
return ;
}
poj1379 模拟退火的更多相关文章
- 【模拟退火】poj1379 Run Away
题意:平面上找一个点,使得其到给定的n个点的距离的最小值最大. 模拟退火看这篇:http://www.cnblogs.com/autsky-jadek/p/7524208.html 这题稍有不同之处仅 ...
- poj-1379 Run Away(模拟退火算法)
题目链接: Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 7982 Accepted: 2391 De ...
- 模拟退火算法(run away poj1379)
http://poj.org/problem?id=1379 Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: ...
- poj1379
poj1379 题意 给出 n 个洞的坐标,要求找到一点使得这一点距离最近洞的距离最远. 分析 通过这道题学习一下模拟退火算法, 这种随机化的算法,在求解距离且精度要求较小时很有用. 简而言之,由随机 ...
- poj-2420 A Star not a Tree?(模拟退火算法)
题目链接: A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5219 Accepte ...
- bzoj3680模拟退火
看题意就是一道数学物理题,带权费马点 --这怎么是数学了,这也是物理的 所以要用物理方法,比如FFF 国际著名oi选手miaom曾说 模拟退火初温可以低,但是最好烧个几千次 国际著名物理课代表+1 ...
- 无题的题 & 模拟退火...
题意: 给你不超过8条一端在圆心的半径,求他们组成的凸包的最大面积. SOL: 正解怎么搞啊不会啊...然后昨天毛爷爷刚讲过模拟退火...那么就打一个吧... 然后就T了,不过三角形的部分分妥妥的.. ...
- [POJ2069]Super Star(模拟退火)
题目链接:http://poj.org/problem?id=2069 题意:求一个半径最小的球,使得它可以包围住所有点. 模拟退火,圆心每次都去找最远那个点,这样两点之间的距离就是半径,那么接下来移 ...
- [POJ2420]A Star not a Tree?(模拟退火)
题目链接:http://poj.org/problem?id=2420 求费马点,即到所有其他点总和距离最小的点. 一开始想枚举一个坐标,另一个坐标二分的,但是check的时候还是O(n)的,复杂度相 ...
随机推荐
- POJ 3714 Raid
Description After successive failures in the battles against the Union, the Empire retreated to its ...
- Ros与Vrep平台搭建
参考资料: ROS安装: ros 是一个framework 和Android有点像,内核用的linux.Ros提供了一种供机器人开发者迅速上手的一个平台, 可以快速搭建自己的应用,利用ros下面自带的 ...
- node基础05:路由基础
1.基础实例 //server.js var http = require("http"); var url = require("url"); var rou ...
- ORA-06519: active autonomous transaction detected and rolled back
这个问题一般怎么解决 ?现在忙 待会贴详细代码 先给些路子..给位大大们 引用 楼主 green3365302 的回复: 这个问题一般怎么解决 ?现在忙 待会贴详细代码 先给些路子..给位大大们 ...
- python 二叉树
class Node(object): def __init__(self, data=None, left=None, right=None): self.data = data self.left ...
- DTCMS插件的制作实例电子资源管理(二)Admin后台页面编写
总目录 插件目录结构(一) Admin后台页面编写(二) 前台模板页编写(三) URL重写(四) 本实例旨在以一个实际的项目中的例子来介绍如何在dtcms中制作插件,本系列文章非入门教程,部分逻辑实现 ...
- JavaScript的理解记录(3)
---接上篇 一.函数: 1. 函数定义后直接执行:var f = (function(x){ return x*10}(10)); 2. 函数的调用有四种方式: 作为函数:作为方法:作为构造函 ...
- android之短信拦截器
下面通过短信拦截器来介绍短信中的广播 布局文件 在布局文件中可以设置需要拦截的号码 <?xml version="1.0" encoding="utf-8" ...
- htop查看系统负载
htop 是 Linux 系统中的一个互动进程查看器,可以让用户进行交互式操作,可横向或纵向滚动浏览进程列表,支持鼠标操作.用户可以在安装 htop 来监控服务器的负载. 01.下载 https:// ...
- PotPlayer 1.6.52965 美化版|视频播放器
Potplayer播放器,基本上可以解析大部分的视频格式.作为单机版的视频播放器很不错的选择! Potplayer,只为播放而生! exp: 点击下载