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: ...
随机推荐
- sourceTree安装与使用
1,下载并安装 sourceTree http://downloads.atlassian.com/software/sourcetree/windows/SourceTreeSetup_1.6.14 ...
- mybatis一对一关联表查询
先创建一个表 CREATE TABLE teacher( t_id INT PRIMARY KEY AUTO_INCREMENT, t_name ) ); CREATE TABLE class( c_ ...
- Net Core WebAPI
Net Core WebAPI .Net Core WebAPI 基于Task的同步&异步编程快速入门 Task.Result async & await 总结 并行任务(Task)以 ...
- Maven 版 JPA 最佳实践(转)
项目结构图 数据库环境 数据库:MySQL 版本:5.x 数据库名:jpa-demo 用户名密码:root/1234 代码清单 1:数据库脚本: ? 1 2 3 4 5 6 7 8 9 10 11 1 ...
- perl lwp关闭ssl校验
use LWP::UserAgent; use HTTP::Cookies; use HTTP::Headers; use HTTP::Response; use Encode; use File:: ...
- web.xml中servlet, bean, filter, listenr 加载顺序汇总
最终得出结果:先 listener >> filter >> servlet >> spring 所以,如果过滤器中要使用到 bean,可以将spring 的加载 ...
- JAVA GUI学习 - JTable表格组件学习_C ***
/** * JTable高级应用 * @author Wfei * */ public class JTableKnow_C extends JFrame { JTable jTable; MyJMe ...
- Linux下安装VNC Server
操作系统centos6.5,在其之上安装vnc server,可利用windows上的vnc client远程登录. 1. 安装 yum install tigervnc-server.x86_64 ...
- La=LaULb (循环链表)
#include<stdio.h> typedef struct LNode { int data; struct LNode *next; }LNode,*LinkList; void ...
- C# Socket select模型
http://www.cnblogs.com/Clingingboy/archive/2011/07/04/2097806.html http://www.cnblogs.com/RascallySn ...