POJ 1379
模拟退火算法。
随机MAX个点,然后,退火移动,选取距离所有点中最短中最长者即可。理解和我上一篇一样。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
using namespace std;
const int MAXN=1010;
const int MAX=50;
const double inf=1e10;
const double eps=1e-3; struct point {
double x,y;
};
point p[MAXN]; point tar[MAX];
double best[MAXN];
int n; double ans_dis; point s,tp; double tmp_dis;
double X,Y; double getdouble(){
double ret=((rand()*rand())%1000000)*1.0/1e6;
return ret;
}
double dist(point &u,point &v){
return sqrt((u.x-v.x)*(u.x-v.x)+(u.y-v.y)*(u.y-v.y));
} double work(point &t){
double ret=inf;
for(int i=0;i<n;i++){
double tmp=dist(t,p[i]);
ret=min(ret,tmp);
}
return ret;
} int main(){
int cas; bool flag;
scanf("%d",&cas);
srand(time(0));
while(cas--){
scanf("%lf%lf%d",&X,&Y,&n);
for(int i=0;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
for(int i=0;i<MAX;i++){
tar[i].x=getdouble()*X;
tar[i].y=getdouble()*Y;
best[i]=work(tar[i]);
}
double T=100;
for(double t=T;t>eps;t*=0.8){
for(int i=0;i<MAX;i++){
for(int j=0;j<30;j++){
double tmp=getdouble();
if(rand()&1) tmp*=-1;
tp.x=tar[i].x+tmp*t;
tmp=getdouble();
if(rand()&1) tmp*=-1;
tp.y=tar[i].y+tmp*t;
if(tp.y>=0&&tp.y<Y&&tp.x>=0&&tp.x<=X){
double f=work(tp);
if(f>best[i]) {
tar[i]=tp; best[i]=f;
}
}
}
}
}
ans_dis=best[0];
for(int i=0;i<MAX;i++){
double fe=best[i];
if(fe>ans_dis){
s=tar[i];
ans_dis=fe;
}
}
printf("The safest point is (%.1lf, %.1lf).\n",s.x,s.y);
}
return 0;
}
POJ 1379的更多相关文章
- POJ.1379.Run Away(模拟退火)
题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...
- POJ 1379 模拟退火
模拟退火算法,很久之前就写过一篇文章了.双倍经验题(POJ 2420) 题意: 在一个矩形区域内,求一个点的距离到所有点的距离最短的那个,最大. 这个题意,很像二分定义,但是毫无思路,也不能暴力枚举, ...
- POJ 1379 Run Away
题意:有n个陷阱,在X,Y范围内要求出一个点使得这个点到陷阱的最小距离最大. 思路:模拟退火,随机撒入40个点,然后模拟退火随机化移动. (这题poj坑爹,加了srand(time(NULL))不能交 ...
- POJ 1379 Run Away 【基础模拟退火】
题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...
- poj 1379 Run Away 模拟退火 难度:1
Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6482 Accepted: 1993 Descript ...
- POJ 1379 (随机算法)模拟退火
题目大意: 给定一堆点,找到一个点的位置使这个点到所有点中的最小距离最大 这里数据范围很小,精度要求也不高,我们这里可以利用模拟退火的方法,随机找到下一个点,如果下一个点比当前点优秀就更新当前点 参考 ...
- poj 1379 模拟退火法
/* 模拟退火法: 找到一些随机点,从这些点出发,随机的方向坐标向外搜索: 最后找到这些随机点的最大值: 坑://if(xx>-eps&&xx<x+eps&& ...
- 【HDOJ】1109 Run Away
基础模拟退火. /* poj 1379 */ #include <iostream> #include <cstdio> #include <cstdlib> #i ...
- poj和hdu部分基础算法分类及难度排序
最近想从头开始刷点基础些的题,正好有个网站有关于各大oj的题目分类(http://www.pythontip.com/acm/problemCategory),所以写了点脚本把hdu和poj的一些题目 ...
随机推荐
- bzoj 1024 [ SCOI 2009 ] 生日快乐 —— 递归
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1024 因为每次把一块切成两块,所以可以枚举从哪里切开,然后递归求解: 一开始用了不太对的贪心 ...
- 96.extjs 页面
1.登录js /** * @author sux * @desc 登录 */ Ext.onReady(function(){ Ext.QuickTips.init(); //错误信息显示必须 var ...
- go 函数高级运用
一.函数作用域 说明 作用域的定义:已声明标识符所表示的常量.类型.变量.函数或包在源代码中的作用范围 在说函数作用域之前,先简单说一下局部变量和局变量 简单的说: 全局变量:在一个文件中,任何地方都 ...
- php获取当地时间 time zone
PHP5.2.4之前的版本无需设置时区.下面是修改PHP时区的三个办法. 1.修改PHP.ini这个文件 找到date.timezone这行,去掉前面的分号,改成: Java代码 date.tim ...
- JavaScript(基于react+dva)
变量声明 const 和 let:分别表示常量和变量 模板字符串 const user = 'world'; console.log(`hello ${user}`); // hello world ...
- 努比亚(nubia) V18 NX612J 解锁BootLoader 并刷入recovery ROOT
recovery制作来自绯色玻璃 努比亚(nubia) V18 NX612J 解锁BootLoader 并刷入recovery ROOT 工具下载链接:https://pan.baidu.com/s/ ...
- SLAM: Structure From Motion-移动中三维场景重建
wiki链接:https://en.wikipedia.org/wiki/Structure_from_motion 三维重建: 三维物体建模总结 1. 视野内三维物体重建 : Kinect fusi ...
- The as! Operator
Prior to Swift 1.2, the as operator could be used to carry out two different kinds of conversion, de ...
- webpack学习(六)—webpack+react+es6(第3篇)
接上篇 : webpack学习(六)—webpack+react+es6(第2篇) 上篇其实是有问题的,问题在取服务器数据这块.this.props 表示那些一旦定义,就不再改变的特性,而 this. ...
- 解决vcenter 6.0 vcsa安装插件时报错的问题
在安装vCenter 6.0 vsca的时候,安装插件到第二个的时候,会报出一个windows installer的错误.需要联系软件管理员或者技术支持的一个error. 经过多次的测试,我终于找到了 ...