poj 1379 模拟退火法
/*
模拟退火法:
找到一些随机点,从这些点出发,随机的方向坐标向外搜索;
最后找到这些随机点的最大值;
坑://if(xx>-eps&&xx<x+eps&&yy>-eps&&yy<eps+y) {不知道为什么这个判断方式错误??????
*/
#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
#define pi acos(-1.0)
#define N 1100
#define inf 1000000000000
#define eps 1e-8
using namespace std;
double x,y;
int n;
struct node {
double u,v,dis;
}f[N],endd,ff[N];
double diss(double x,double y,int i) {
return sqrt((x-f[i].u)*(x-f[i].u)+(y-f[i].v)*(y-f[i].v));
}
double Mindis(double x,double y) {
double minn=1.0*inf,ss;
int i;
for(i=1;i<=n;i++) {
ss=diss(x,y,i);
if(minn>ss)
minn=ss;
}
return minn;
}
void compute() {
int i,j;
double xx,yy;
for(i=1;i<=20;i++) {//先随机出来一些点
ff[i].u=(rand()%1000+1)/1000.0*x;
ff[i].v=(rand()%1000+1)/1000.0*y;
ff[i].dis=Mindis(ff[i].u,ff[i].v);
}
double T=sqrt(1.0*x*x+1.0*y*y);
double rate=0.9;
while(T>eps) {
for(i=1;i<=20;i++)//对于这些点分别向外搜
for(j=1;j<=30;j++) {//随机30个半径来搜索,更新,得到每个点可以到达的最远距离
double ran=(rand()%1000+1)/1000.0*pi*10;
xx=ff[i].u+cos(ran)*T;
yy=ff[i].v+sin(ran)*T;
//if(xx>-eps&&xx<x+eps&&yy>-eps&&yy<eps+y) {不知道为什么这个判断方式错误??????
if(xx<0.0||xx>x||yy<0.0||yy>y)continue;
double di=Mindis(xx,yy);
if(ff[i].dis<di) {
ff[i].dis=di;
ff[i].u=xx;
ff[i].v=yy;
}
}
T*=rate;//退火率
}
for(i=1;i<=20;i++)//找到最大的一个
if(endd.dis<ff[i].dis)
endd=ff[i];
return ;
}
int main() {
// printf("%d\n",(rand()%1000+1)/1000.0*2*pi);
int m,i,j,k,t;
scanf("%d",&t);
while(t--) {
scanf("%lf%lf%d",&x,&y,&n);
for(i=1;i<=n;i++)
scanf("%lf%lf",&f[i].u,&f[i].v);
endd.dis=-1;
compute();
printf("The safest point is (%.1f, %.1f).\n",endd.u,endd.v);
}
return 0;
}
poj 1379 模拟退火法的更多相关文章
- POJ 1016 模拟字符串
Numbers That Count Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20396 Accepted: 68 ...
- unity, 模拟退后台
//simulateSwitchToBackground.cs using UnityEngine;using System.Collections;using System.Collections. ...
- POJ 1208 模拟
2017-08-28 15:07:16 writer:pprp 好开心,这道题本来在集训的时候做了很长很长时间,但是还是没有做出来,但是这次的话,只花了两个小时就做出来了 好开心,这次采用的是仔细分析 ...
- POJ - 3087 模拟 [kuangbin带你飞]专题一
模拟洗牌的过程,合并两堆拍的方式:使先取s2,再取s1:分离成两堆的方式:下面C张放到s1,上面C张到s2.当前牌型与第一次相同时,说明不能搜索到答案. AC代码 #include<cstdio ...
- POJ.1379.Run Away(模拟退火)
题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...
- POJ 1379 模拟退火
模拟退火算法,很久之前就写过一篇文章了.双倍经验题(POJ 2420) 题意: 在一个矩形区域内,求一个点的距离到所有点的距离最短的那个,最大. 这个题意,很像二分定义,但是毫无思路,也不能暴力枚举, ...
- Shuffle'm Up POJ - 3087(模拟)
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15249 Accepted: 6962 Des ...
- POJ 1471 模拟?
题意:求最大无坏点三角形 思路: 模拟? (为什么我模拟过了...) 有人用 DP,有人用 搜索... // by SiriusRen #include <cstdio> #include ...
- POJ 1951 模拟
思路: 坑爹模拟毁我一生 给两组数据: 输入: YOURE TRAVELING THROUGH ANOTHER DIMENSION A DIMENSION NOT OF SIGHT. 输出: YR T ...
随机推荐
- bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【Floyd】
弗洛伊德之后按序列加起来即可 #include<iostream> #include<cstdio> #include<algorithm> using names ...
- golang——log包学习
log包实现了简单的日志服务. 1.func New(out io.Writer, prefix string, flag int) *Logger New创建一个Logger. 参数out设置日志信 ...
- Focusky的下载、安装、注册和使用(动画演示大师)
一.下载 二.安装 三.使用 四.注册 五.附录 非常感谢Focusky官方团队开发并提供实用的这么一款软件!!! 一.下载 http://www.focusky.com.cn/ 二.安装 三.使用 ...
- 使用vs2010打开vs2015的项目
本来在单位项目一直使用vs2010写,五一放假拿回家 ,用vs2015捣鼓了一下 当然向下兼容打开毫无问题,结果回来悲催了,用vs2010打不开了 ,打不开. 记得以前有个转换向导,可是这次没看见,一 ...
- mac os 10.10解决pod问题
转一下 http://leancodingnow.com/how-to-get-cocoapods-work-on-yosemite/
- 诊断:ORA-38760: This database instance failed to turn on flashback database
$ oerr ora 38760 38760, 00000, "This database instance failed to turn on flashback database&quo ...
- 诊断:ORA-01919: role ‘PLUSTRACE’ does not exist
如下错误 SQL> grant plustrace to scott; grant plustrace to scott * ERROR at line 1: ORA-01919: role ' ...
- 08css、JS
08.css.JS-2018/07/18 1.css的属性 文字属性:font-size:大小,font-family字体类型,font-color:颜色 文本颜色:color:颜色,test-dec ...
- P1036 选数(DFS)
题目 https://www.luogu.org/problemnew/show/P1036 思路 搜索,使用递归实现dfs,所有数字遍历一遍,当取遍所有数组的index(扫了一遍,并非一定是选取了) ...
- 「 CODE[VS] P2853 」 方格游戏
题目大意 给定一张 $n\times n$ 的网格.每个格子上都有一个系数 $a$,先下 $A$ 和 $B$ 两人选择两条 $(1,1)\rightarrow (n,n)$ 路径.要求着两条路径不能相 ...