poj-1379 Run Away(模拟退火算法)
题目链接:
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 7982 | Accepted: 2391 |
Description
Input
Output
Sample Input
3
1000 50 1
10 10
100 100 4
10 10
10 90
90 10
90 90
3000 3000 4
1200 85
63 2500
2700 2650
2990 100
Sample Output
The safest point is (1000.0, 50.0).
The safest point is (50.0, 50.0).
The safest point is (1433.0, 1669.8).
题意:求矩形里的一个点,使这个点到所有已知点的最小距离尽量大;
思路:看网上说是一个模拟退火算法就简单的学了一下,随机取一些点然后在这些点一点范围内再随机的取点,取得点更符合就更新,指导温度冷却到一定程度就可以得到答案了;
AC代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <algorithm>
using namespace std;
const int num=;//每次的子集有多少元素,就是你要选多少个点进行迭代
const int cnt=;//每次一个点要随机的生成多少个点
const double inf=1e14+;
const double PI=acos(-1.0);
int fx,fy,n;
double x[],y[],px,py;
struct node
{
double X,Y,dis;
};
node ans[];
double get_dis(double a,double b,double c,double d)
{
return sqrt((c-a)*(c-a)+(d-b)*(d-b));
}
void Iint()
{
for(int i=;i<num;i++)
{
ans[i].X=1.0*(rand()%+)/*fx;
ans[i].Y=1.0*(rand()%+)/*fy;
ans[i].dis=inf;
for(int j=;j<n;j++)
{
ans[i].dis=min(ans[i].dis,get_dis(ans[i].X,ans[i].Y,x[j],y[j]));
}
}
}
int main()
{
int t;
scanf("%d",&t);
srand((unsigned)time(NULL));
while(t--)
{
scanf("%d%d%d",&fx,&fy,&n);
for(int i=;i<n;i++)
{
scanf("%lf%lf",&x[i],&y[i]);
}
Iint();
double temp=max(fx*1.0,fy*1.0)/(sqrt(1.0*n));
while(temp>=0.001)
{
for(int i=;i<num;i++)
{
px=ans[i].X;
py=ans[i].Y;
for(int j=;j<cnt;j++)
{
double s=PI**(rand()%)/,dx,dy;
dx=px+cos(s)*temp;
dy=py+sin(s)*temp;
if(dx<||dx>fx*1.0||dy<||dy>fy*1.0)continue;
double cur=inf;
for(int k=;k<n;k++)
{
cur=min(cur,get_dis(dx,dy,x[k],y[k]));
}
if(cur>ans[i].dis)
{
ans[i].X=dx;
ans[i].Y=dy;
ans[i].dis=cur;
}
} }
temp*=0.83;
}
double ans_dis=,ans_x,ans_y;
for(int i=;i<num;i++)
{
if(ans[i].dis>ans_dis)
{
ans_x=ans[i].X;
ans_y=ans[i].Y;
ans_dis=ans[i].dis;
}
}
printf("The safest point is (%.1lf, %.1lf).\n",ans_x,ans_y);
}
return ;
}
poj-1379 Run Away(模拟退火算法)的更多相关文章
- PKU 1379 Run Away(模拟退火算法)
题目大意:原题链接 给出指定的区域,以及平面内的点集,求出一个该区域内一个点的坐标到点集中所有点的最小距离最大. 解题思路:一开始想到用随机化算法解决,但是不知道如何实现.最后看了题解才知道原来是要用 ...
- POJ.1379.Run Away(模拟退火)
题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...
- poj 1379 Run Away 模拟退火 难度:1
Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6482 Accepted: 1993 Descript ...
- POJ 1379 Run Away 【基础模拟退火】
题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...
- POJ 1379 Run Away
题意:有n个陷阱,在X,Y范围内要求出一个点使得这个点到陷阱的最小距离最大. 思路:模拟退火,随机撒入40个点,然后模拟退火随机化移动. (这题poj坑爹,加了srand(time(NULL))不能交 ...
- 模拟退火算法(run away poj1379)
http://poj.org/problem?id=1379 Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: ...
- POJ 1379 模拟退火
模拟退火算法,很久之前就写过一篇文章了.双倍经验题(POJ 2420) 题意: 在一个矩形区域内,求一个点的距离到所有点的距离最短的那个,最大. 这个题意,很像二分定义,但是毫无思路,也不能暴力枚举, ...
- 模拟退火算法-[HDU1109]
模拟退火算法的原理模拟退火算法来源于固体退火原理,将固体加温至充分高,再让其徐徐冷却,加温时,固体内部粒子随温升变为无序状,内能增大,而徐徐冷却时粒子渐趋有序,在每个温度都达到平衡态,最后在常温时达到 ...
- 初探 模拟退火算法 POJ2420 HDU1109
模拟退火算法来源于固体退火原理,更多的化学物理公式等等这里不再废话,我们直接这么来看 模拟退火算法简而言之就是一种暴力搜索算法,用来在一定概率下查找全局最优解 找的过程和固体退火原理有所联系,一般来讲 ...
随机推荐
- 工具类之Condition
再次看到Condition,第一感觉还是觉得它和Mutex的功能是一样的,没必要存在.心里这么想,其实自己也知道怎么可能多余呢?老老实实的再分析一下代码,这次一定要把理解出来的内容记下来!都怪平时写代 ...
- JVM调优- jmap(转)
http://blog.csdn.net/fenglibing/article/details/6411953 1.介绍 打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些 ...
- poj2891(线性同余方程组)
一个exgcd解决一个线性同余问题,多个exgcd解决线性同余方程组. Strange Way to Express Integers Time Limit: 1000MS Memory Limi ...
- mac查看网页时翻页
1 fn + 上下 翻页 2 command + 上下 一下子到文档头和文档尾部
- TFS中工作项的定制- 字段功能定义
参考,翻译此页面All FIELD XML Elements Reference(http://msdn.microsoft.com/en-us/library/ms194953.aspx) 对于每一 ...
- OC中第三方库MJExtension的使用
MJExtension是一套常用的"字典和模型之间互相转换"的框架,在项目中也使用过,现在记录一下.随着Swift的普及,在Swift中也有一个类似功能的框架HandyJSON 也 ...
- 北京君正集成电路的Newton平台--穿戴式
版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/hellomxj1/article/details/25324125 Newton1开发平台 • 很适合 ...
- Python——Numpy的random子库
NumPy的random子库 np.random.* np.random.rand() np.random.randn() np.random.randint() import numpy as np ...
- SpringBoot学习笔记(2):引入Spring Security
SpringBoot学习笔记(2):用Spring Security来保护你的应用 快速开始 本指南将引导您完成使用受Spring Security保护的资源创建简单Web应用程序的过程. 参考资料: ...
- MVC ViewBag不能使用在工程文件中添加引用
在工程文件中 <ItemGroup> // ... </ItemGroup> 添加引用 <Reference Include="Microsoft.CSharp ...