poj 1379 Run Away 模拟退火 难度:1
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 6482 | Accepted: 1993 |
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). 思路:直接按照题解做的,首先列举30个随机点,然后分别进行短距离的随机尝试
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
const double Pi=acos(-1.0);
const double eps=1e-3;
const double inf=1e20;
double px[31],py[31],d[31],x[1111],y[1111];
double caldis(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
int T;
scanf("%d",&T);
srand(9876543);
while(T--){
int a,b,m;
scanf("%d%d%d",&a,&b,&m);
for(int i=0;i<m;i++){
scanf("%lf%lf",x+i,y+i);
}
for(int i=0;i<30;i++){
px[i]=(double)(rand()%1000+1)/1000.000*a;
py[i]=(double)(rand()%1000+1)/1000.000*b;
d[i]=inf;
for(int j=0;j<m;j++)d[i]=min(d[i],caldis(px[i],py[i],x[j],y[j]));
}
double delta=double(max(a,b))/(sqrt(1.0*m));
while(delta>eps){
for(int i=0;i<30;i++){
double tx=px[i],ty=py[i];
for(int j=0;j<30;j++){
double theta=(double)(rand()%1000+1)/1000.000*10*Pi;
double dx=delta*cos(theta);
double dy=delta*sin(theta);
tx+=dx;ty+=dy;
if(tx<0||tx>a||ty<0||ty>b){tx-=dx;ty-=dy;continue;}
double td=inf;
for(int k=0;k<m;k++)td=min(td,caldis(tx,ty,x[k],y[k]));
if(td>d[i]){
d[i]=td;px[i]=tx;py[i]=ty;
}
tx-=dx;ty-=dy;
}
}
delta*=0.9;
}
double ans=0;int ind=0;
for(int i=0;i<30;i++){
if(d[i]>ans){
ind=i;
ans=d[i];
}
}
printf("The safest point is (%.1f, %.1f).\n",px[ind],py[ind]);
}
return 0;
}
poj 1379 Run Away 模拟退火 难度:1的更多相关文章
- POJ.1379.Run Away(模拟退火)
题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...
- POJ 1379 Run Away 【基础模拟退火】
题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...
- PKU 1379 Run Away(模拟退火算法)
题目大意:原题链接 给出指定的区域,以及平面内的点集,求出一个该区域内一个点的坐标到点集中所有点的最小距离最大. 解题思路:一开始想到用随机化算法解决,但是不知道如何实现.最后看了题解才知道原来是要用 ...
- POJ 1379 Run Away
题意:有n个陷阱,在X,Y范围内要求出一个点使得这个点到陷阱的最小距离最大. 思路:模拟退火,随机撒入40个点,然后模拟退火随机化移动. (这题poj坑爹,加了srand(time(NULL))不能交 ...
- POJ 1379 模拟退火
模拟退火算法,很久之前就写过一篇文章了.双倍经验题(POJ 2420) 题意: 在一个矩形区域内,求一个点的距离到所有点的距离最短的那个,最大. 这个题意,很像二分定义,但是毫无思路,也不能暴力枚举, ...
- POJ 1379 (随机算法)模拟退火
题目大意: 给定一堆点,找到一个点的位置使这个点到所有点中的最小距离最大 这里数据范围很小,精度要求也不高,我们这里可以利用模拟退火的方法,随机找到下一个点,如果下一个点比当前点优秀就更新当前点 参考 ...
- poj-1379 Run Away(模拟退火算法)
题目链接: Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 7982 Accepted: 2391 De ...
- 【BZOJ1844/2210】Pku1379 Run Away 模拟退火
[BZOJ1844/2210]Pku1379 Run Away 题意:矩形区域中有一堆点,求矩形中一个位置使得它到所有点的距离的最小值最大. 题解:模拟退火的裸题,再调调调调调参就行了~ #inclu ...
- poj 2069 Super Star —— 模拟退火
题目:http://poj.org/problem?id=2069 仍是随机地模拟退火,然而却WA了: 看看网上的题解,都是另一种做法——向距离最远的点靠近: 于是也改成那样,竟然真的A了...感觉这 ...
随机推荐
- eclipse中Web Deployment Assembly与build path作用
java Build path是编译路径设置,主要用来设置源代码的编译路径默认是default output folder Web Deployment Assembly是eclipse中的发布路径设 ...
- 高通camera结构(摄像头基础介绍)
摄像头基础介绍 一.摄像头结构和工作原理. 拍摄景物通过镜头,将生成的光学图像投射到传感器上,然后光学图像被转换成电信号,电信号再经过模数转换变为数字信号,数字信号经过DSP加工处理,再被送到电脑中进 ...
- 20145314郑凯杰 《Java程序设计》第8周学习总结
20145314郑凯杰 <Java程序设计>第8周学习总结 教材学习内容总结 代码已托管 第十五章 通用API ①日志: 日志对信息安全意义重大,审计.取证.入侵检测等都会用到日志信息 使 ...
- strcpy、sprintf、memcpy的区别
char*strcpy(char *dest, const char *src); 其对字符串进行操作,完成从源字符串到目的字符串的拷贝,当源字符串的大小大于目的字符串的最大存储空间后,执行该操作会出 ...
- kernel command line 参数详解
Linux内核在启动的时候,能接收某些命令行选项或启动时参数.当内核不能识别某些硬件进而不能设置硬件参数或者为了避免内核更改某些参数的值,可以通过这种方式手动将这些参数传递给内核. 如果不使用启动管 ...
- 机器学习之线性回归(纯python实现)][转]
本文转载自:https://juejin.im/post/5a924df16fb9a0634514d6e1 机器学习之线性回归(纯python实现) 线性回归是机器学习中最基本的一个算法,大部分算法都 ...
- 4.9版本linux内核的ina220电流检测芯片源码在哪里
答:在drivers/hwmon/ina2xx.c中,内核配置项为CONFIG_SENSORS_INA2XX Location: -> Device Drivers -> Hardware ...
- linux如何以十六进制格式来查看任意文件
答:vim+xxd 使用方法如下: 1.vim -b file.txt 2.在vim的命令行模式下对文件进行16进制转换 输入:%!xxd 3.在vim的命令行模式下回到正常格式 输入:%!xxd - ...
- centos redis 3.2.11 安装与配置
centos 7 下载解压 wget http://download.redis.io/releases/redis-3.2.11.tar.gz tar xzf redis-3.2.11.tar.gz ...
- LeetCode——3Sum
1. Question Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? ...