基础模拟退火。

 /* poj 1379 */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; #define MAXN 1005
#define INF 999999
#define MAXM 25 typedef struct {
double x, y;
} Point_t; const double eps = 1e-;
const double next = 0.9;
const double PI = acos(-1.0);
double X, Y;
int n;
Point_t points[MAXN];
Point_t rpoints[MAXM];
double rdis[MAXM]; inline bool check(Point_t p) {
return p.x< || p.x>=X || p.y< || p.y>=Y;
} double cross(Point_t a, Point_t b, Point_t c) {
return (b.x-a.x)*(c.y-a.y) - (c.x-a.x)*(b.y-a.y);
} double Length(Point_t a, Point_t b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} double solve(Point_t p) {
int i, j, k;
double ret = INF; for (i=; i<n; ++i) {
ret = min(ret, Length(p, points[i]));
} return ret;
} int main() {
int t;
int i, j, k;
Point_t p, pp;
double step, angle;
double ans, tmp; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif scanf("%d", &t);
while (t--) {
scanf("%lf %lf %d", &X, &Y, &n);
for (i=; i<n; ++i)
scanf("%lf %lf", &points[i].x, &points[i].y);
for (i=; i<MAXM; ++i) {
rpoints[i].x = (rand()%+)/1000.0*X;
rpoints[i].y = (rand()%+)/1000.0*Y;
rdis[i] = solve(rpoints[i]);
}
step = max(X, Y)/sqrt(1.0*n);
while (step > eps) {
for (i=; i<MAXM; ++i) {
p = rpoints[i];
for (j=; j<MAXM; ++j) {
angle = (rand()%+)/.**PI;
pp.x = p.x + cos(angle)*step;
pp.y = p.y + sin(angle)*step;
if (check(pp))
continue;
tmp = solve(pp);
if (tmp > rdis[i]) {
rpoints[i] = pp;
rdis[i] = tmp;
}
}
}
step *= next;
}
double ans = -1.0;
k = ;
for (i=; i<MAXM; ++i) {
if (rdis[i] > ans) {
ans = rdis[i];
k = i;
}
}
printf("The safest point is (%.1lf, %.1lf).\n", rpoints[k].x, rpoints[k].y);
} return ;
}

【HDOJ】1109 Run Away的更多相关文章

  1. 【vue】npm run mock & npm run dev 无法同时运行的解决

    [关于系统,没注明的都是windows系统,若以后用的是mac系统则会另外备注] 当项目数据是通过mock搭建而成(参照:[vue]本地开发mock数据支持)时,运行mock服务器和项目的命令 就参照 ...

  2. 【HDOJ】1474 Always On the Run

    普通DP.基本和floyd一个思路. /* 1474 */ #include <cstdio> #include <cstring> #include <cstdlib& ...

  3. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  4. 【云计算】docker run详解

    Docker学习总结之Run命令介绍 时间 2015-01-21 17:06:00                                               博客园精华区       ...

  5. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  6. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  7. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  8. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  9. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

随机推荐

  1. MVC 无法将类型“System.Collections.Generic.List<AnonymousType#1>”隐式转换为“System.Collections.Generic.IList<Mvc3Modeltest.Models.Movie>”。存在一个显式转换(是否缺少强制转换?))

    1.问题: 2.解决方案:强制指定类型. 解决之.

  2. [疑惑与解答] WxPython In Action -1

    在学<活学活用wxPython>第三章的时候,我遇到一点疑惑,那就是下面语句的区别是什么 例 3.1 第4,5行: panel = wx.Panel(self, -1) button = ...

  3. MySQL Replication, 主从和双主配置

    MySQL Replication, 主从和双主配置 MySQL的Replication是一种多个MySQL的数据库做主从同步的方案,特点是异步,广泛用在各种对MySQL有更高性能,更高可靠性要求的场 ...

  4. discuz! X3 门户文章添加字段

    1. 首先需要去数据表里[llgp_portal_article_title]手动添加需要添加的字段. (注意: 数据表前缀依据自己的设置而定) 2. 修改模版template\default\por ...

  5. Bellman_ford POJ 3259 Wormholes

    Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 41728   Accepted: 15325 Descr ...

  6. Django Errors Archive

    记录使用 Django 开发中遇到的问题,备用 1. 版本要选好,最好安装上 pip,可以省很多麻烦 2. 如果使用 Postgresql,选 8.1 之后的版本,免去 Retruning 之类的错误 ...

  7. .net 计算当前时间距离今晚00:00:00还有多少分多少秒

    string dateDiff = null; DateTime DateTime1 = DateTime.Now; //第二天的0点00分00秒 DateTime DateTime2 = DateT ...

  8. ajax调试兼容性

    <script type="text/javascript"> if(typeof ActiveXObject!= 'undefined'){ var x = new ...

  9. 【USACO 2.1.1】城堡

    [题目描述] 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特别的礼物:一张“幸运爱尔兰”(一种彩票).结果这张彩票让他获得了这次比赛唯一的奖品— ...

  10. backbone学习笔记(一)

    因为工作的需要,从今天起对backbone的学习过程做下记录. 学习计划: 1.1周看基本知识(2014/1/18-2014/1/25) 2.基本知识总结(2014/1/26) 3.半周按教程写hel ...