基础模拟退火。

 /* 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. UVA 11212 IDA*

    移动一块连续的区间使得数列递增.问最少次数. 直接IDA*暴搜,只是我没有想到A*函数,所以就随手写了个连续递增块数作为估价函数,WA了,然后除以2,还是WA,除以3,WA,除以4...过了= = # ...

  2. 把安卓源代码中的system app独立出来,像开发普通app那样开发

          个人建议首先依照android源码的ide/eclipse中的格式化xml和import导入到你编译的eclipse中,假设你编译的android源码是2.3以上的版本号的,建议用JDK6 ...

  3. poj 3154 Graveyard 贪心

    //poj 3154 //sep9 #include <iostream> #include <cmath> using namespace std; double a[204 ...

  4. C# 读取XML文件示例

    有关XML文件编写规范,请参考:http://www.w3school.com.cn/xml/index.aspXML内容如下(文件名为:Information.xml):浏览器显示: <?xm ...

  5. 【原创】贴片电容的测量方法。。。这是我从自己QQ空间转过来的,本人实操!

    电容不工作一般分为3种情况,漏电.击穿.无电容.一般检测用万用表检测阻值一般调在10K-20K为测量标准,特别是贴片电容.把万用表的笔尖点在贴片电容的两侧,如下图测量: l1.jpg l2.jpg l ...

  6. POJ 2559 Largest Rectangle in a Histogram (单调栈或者dp)

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15831 ...

  7. MySQL存储过程(一)

    1.1 CREATE  PROCEDURE (创建) CREATE PROCEDURE存储过程名 (参数列表) BEGIN SQL语句代码块 END 注意: 由括号包围的参数列必须总是存在.如果没有参 ...

  8. CSS 让标点符号不出现在行首

    word-break:break-all; 这条语句的作用是让语句到达边界的时候自动换行,但是正是这个样式让标点符号跑到了行首. 语法: word-break : normal | break-all ...

  9. Linq101-QueryExecution

    using System; using System.Linq; namespace Linq101 { class QueryExecution { /// <summary> /// ...

  10. 删除重复记录的SQL语句

    1.所有字段均重复的记录(重复记录保留一条) Select distinct * into #Tmp from tblName Drop table tblName Select * into tbl ...