POJ 1379 Run Away 【基础模拟退火】
题意:找出一点,距离所有所有点的最短距离最大
二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的。
Source Code:
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
#include <algorithm>
#define LL long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1.0) using namespace std; const int inf = 0x3f3f3f3f;
const int N = ;
const int L = ; int t,n;
double X ,Y, best[]; struct Point{
double x,y;
bool check(){
if(x > -eps && x < eps + X && y > -eps && y < eps + Y)
return true;
return false;
}
}p[],tp[]; double dist(Point p1,Point p2){
return sqrt((p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y));
} double min_dis(Point p0){
double ans = inf;//
for(int i = ; i < n; ++i)
ans = min(ans,dist(p[i],p0));//
return ans;
} Point rand_point(double x, double y){
Point c;
c.x = (rand() % + ) / 1000.0 * x;
c.y = (rand() % + ) / 1000.0 * y;
return c;
} int main(){
srand(time(NULL));
scanf("%d",&t);
while(t--){
scanf("%lf%lf%d",&X,&Y,&n);
for(int i = ; i < n; ++i)
scanf("%lf%lf",&p[i].x,&p[i].y);
for(int i = ; i < N; ++i){
tp[i] = rand_point(X, Y);
best[i] = min_dis(tp[i]);
}
double step = max(X,Y) / sqrt(1.0 * n);
while(step > 1e-){
for(int i = ; i < N; ++i){
Point cur;
Point pre = tp[i];
for(int j = ; j < L; ++j){
double angle = (rand() % + ) / 1000.0 * * pi;
cur.x = pre.x + cos(angle) * step;
cur.y = pre.y + sin(angle) * step;
if(!cur.check()) continue;
double tmp = min_dis(cur);
if(tmp > best[i]){//
tp[i] = cur;
best[i] = tmp;
}
}
}
step *= 0.85;
}
int idx = ;
for(int i = ; i < N; ++i){
if(best[i] > best[idx]){//
idx = i;
}
}
printf("The safest point is (%.1f, %.1f).\n",tp[idx].x,tp[idx].y);
//printf("%.1f\n",best[idx]);
}
return ;
}
POJ 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
题意:有n个陷阱,在X,Y范围内要求出一个点使得这个点到陷阱的最小距离最大. 思路:模拟退火,随机撒入40个点,然后模拟退火随机化移动. (这题poj坑爹,加了srand(time(NULL))不能交 ...
- POJ 1379 模拟退火
模拟退火算法,很久之前就写过一篇文章了.双倍经验题(POJ 2420) 题意: 在一个矩形区域内,求一个点的距离到所有点的距离最短的那个,最大. 这个题意,很像二分定义,但是毫无思路,也不能暴力枚举, ...
- PKU 1379 Run Away(模拟退火算法)
题目大意:原题链接 给出指定的区域,以及平面内的点集,求出一个该区域内一个点的坐标到点集中所有点的最小距离最大. 解题思路:一开始想到用随机化算法解决,但是不知道如何实现.最后看了题解才知道原来是要用 ...
- POJ 1379 (随机算法)模拟退火
题目大意: 给定一堆点,找到一个点的位置使这个点到所有点中的最小距离最大 这里数据范围很小,精度要求也不高,我们这里可以利用模拟退火的方法,随机找到下一个点,如果下一个点比当前点优秀就更新当前点 参考 ...
- poj和hdu部分基础算法分类及难度排序
最近想从头开始刷点基础些的题,正好有个网站有关于各大oj的题目分类(http://www.pythontip.com/acm/problemCategory),所以写了点脚本把hdu和poj的一些题目 ...
- POJ 1579-Function Run Fun(内存搜索)
Function Run Fun Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16503 Accepted: 8514 ...
- POJ 3140.Contestants Division 基础树形dp
Contestants Division Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10704 Accepted: ...
随机推荐
- React使用笔记1-React的JSX和Style
React使用笔记1-React的JSX和Style Date: 2015-11-27 20:56 Category: Web Tags: JavaScript Author: 刘理想 [toc] 1 ...
- sql语句分析
show profile是由Jeremy Cole捐献给MySQL社区版本的.默认的是关闭的,但是会话级别可以开启这个功能.开启它可以让MySQL收集在执行语句的时候所使用的资源.为了统计报表,把pr ...
- USB3.0 和usb 2.0的区别
USB3.0拥有10倍于USB2.0的速度,可惜DIY“江湖”险恶,如果咱们不掌握如何识别USB3.0的方法,很容易被JS忽悠.何况,USB3.0主板不等于USB3.0机箱,很多朋友在选购时都忽略了一 ...
- cpu卡,sam卡原理
第一部分 CPU基础知识一.为什么用CPU卡IC卡从接口方式上分,可以分为接触式IC卡.非接触式IC卡及复合卡.从器件技术上分,可分为非加密存储卡.加密存储卡及CPU卡.非加密卡没有安全性,可以任意改 ...
- android 百度最新地图sdk包怎么去除 放大缩小按钮
// 隐藏缩放控件 int childCount = mMapView.getChildCount(); View zoom = null; ; i < childCount; i++) { V ...
- Oracle EBS Web ADI 中的术语
Oracle EBS Web ADI 中的术语 (版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 异步调用异步调用是这样子的,和引入接口表中的数 ...
- 拿出来分享了!VIP珍藏!!!全网最齐全的 DEDECMS模板 全盘下载地址列表!没有你找不到的!
拿出来分享了!VIP珍藏!!!全网最齐全的 DEDECMS模板 网盘地址!没有你找不到的! 模板类型最齐全: ----------------------优美的走起!------------ 一:DE ...
- 去除List列表中反复值(稍作调整,也适合于List<T> 和 List<?>)
方法一 循环元素删除 [c-sharp] view plaincopy public static void removeDuplicate(List list) { for ( int i = 0 ...
- IIS MIME的 映射 网站有些类型的文件不能通过网页访问
在iis中能够浏览所有扩展名的文件时,IIS MIME的 映射 您只能在故障排除过程中将通配符映射添加到 IIS MIME 映射中,以作为一种临时解决方案.确定缺少 MIME 类型是问题的原因后,请删 ...
- input autocomplete 下拉提示+支持中文
js 代码: $.getJSON("/Foreign/Getforeign_routeEndPoint", function (data) { $(" ...