题意

给定一个矩形内的\(n\)个点,在矩形中找一个点,离其他点的最大距离最小。

题解

模拟退火。

这个题需要\(x\)和\(y\)坐标随机动的时候多随机几次。否则就WA了。另外由于随机多次,如果温度变化率太小,就会TLE。

代码

//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream> #define FOPI freopen("in.txt", "r", stdin)
#define FOPO freopen("out.txt", "w", stdout) using namespace std;
typedef long long LL;
const int maxn = 1000 + 5;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const double start_T = 20000; struct Point
{
double x, y, z;
Point() {}
Point(double _x, double _y, double _z = 0):x(_x), y(_y), z(_z) {}
}a[maxn]; int dx[] = {1, 1, 1, -1, -1, -1, 0, 0},
dy[] = {0, 1, -1, 0, 1, -1, -1, 1}; int n;
int X, Y; double dist(Point a, Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + 1e-10);
} double getMax(Point p)
{
double res = 0;
for (int i = 1; i <= n; i++)
res = max(res, dist(a[i], p));
return res;
} double SA()
{
Point p(rand()%X, rand()%Y), to;
double T = start_T, rate = 0.94;
double fx, fy, ans = getMax(p); while(T > eps)
{
double tmp = inf;
for (int times = 1; times <= 20; times++)
for (int i = 0; i < 8; i++)
{
fx = p.x + dx[i] / start_T * T * (rand()%X);
fy = p.y + dy[i] / start_T * T * (rand()%Y); if (fx < 0) fx = 0;
if (fy < 0) fy = 0;
if (fx > X) fx = X;
if (fy > Y) fy = Y; double d = getMax(Point(fx, fy));
if (d < tmp)
{
tmp = d;
to = Point(fx, fy);
}
} T *= rate;
if (tmp < eps) continue; if (tmp < ans || (rand()%1000)/1000.0 < exp(-fabs(ans-tmp)/T*start_T))
{
ans = tmp;
p = to;
}
}
printf("(%.1f,%.1f).\n", p.x, p.y);
return ans;
} int t;
int main()
{
// FOPI;
srand(time(NULL));
while(~scanf("%d%d%d", &X, &Y, &n))
{
for (int i = 1; i <= n; i++)
scanf("%lf%lf", &a[i].x, &a[i].y);
printf("%.1f\n", SA());
}
}

Groundhog Build Home - HDU - 3932(模拟退火)的更多相关文章

  1. HDU 3932 Groundhog Build Home 【基础模拟退火】

    和刚才那道是一模一样 不过求的是最小的,只要稍微修改一下就可以了~ //#pragma comment(linker, "/STACK:16777216") //for c++ C ...

  2. HDU 3932 模拟退火

    HDU3932 题目大意:给定一堆点,找到一个点的位置使这个点到所有点中的最大距离最小 简单的模拟退火即可 #include <iostream> #include <cstdio& ...

  3. hdu 3932 Groundhog Build Home

    Groundhog Build Home Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  4. hdu 2215 & hdu 3932(最小覆盖圆)

    Maple trees Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. hdu 3932 Groundhog Build Home —— 模拟退火

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3932 找一个位置使距离最远的点的距离最小: 上模拟退火: 每次向距离最远的点移动,注意判断一下距离最远的点 ...

  6. hdu 3932 Groundhog Build Home——模拟退火

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3932 注意平均值与最远的点距离为0的情况.所以初值设成-1,这样 id 就不会乱.不过设成0也可以.注意判 ...

  7. HDU 3932

    http://acm.hdu.edu.cn/showproblem.php?pid=3932 一定范围的平面上给一些点,求到这些点的最大距离最小,和上一题的题意正好相反,稍微改一下就可以 这个问题又叫 ...

  8. hdu 5017 模拟退火/三分求椭圆上离圆心最近的点的距离

    http://acm.hdu.edu.cn/showproblem.php?pid=5017 求椭圆上离圆心最近的点的距离. 模拟退火和三分套三分都能解决 #include <cstdio> ...

  9. hdu 5017 模拟退火算法

    hdu 5017 http://blog.csdn.net/mypsq/article/details/39340601 #include <cstdio> #include <cs ...

随机推荐

  1. AngularJS实现 购物车

    <!DOCTYPE html> <html> <head> <meta charset = "utf-8"> <script ...

  2. chroot 的应用

    http://www.williamlong.info/archives/3864.html http://my.oschina.net/u/1590519/blog/342576

  3. C#基础知识图谱

  4. mysql服务器系统优化

    1.选择合适的IO调度 对于mysql的系统,如果是SSD,那么应该使用NOOP调度算法,如果是磁盘,就应该使用Deadline调度算法.默认是CFQ echo dealine > /sys/b ...

  5. Win 10 Google 云端硬盘 网页证书问题导致无法登录解决办法

    操作方法 按照图示,将以下3项勾去并确定. 效果 设置以后,可成功访问:

  6. [Asp.Net] Form验证中 user.identity为false

    这个方法可以是user.identity设置为true FormsAuthentication.SetAuthCookie(Username, true); 但是要开启form验证, 在配置文件中 & ...

  7. shell 快速浏览

    总结自: https://github.com/qinjx/30min_guides/blob/master/shell.md: http://blog.itpub.net/14293828/view ...

  8. 【转】iOS开发之压缩与解压文件

    ziparchive是基于开源代码”MiniZip”的zip压缩与解压的Objective-C 的Class,使用起来非常的简单方法:从http://code.google.com/p/ziparch ...

  9. Nginx学习记录(二)

    1. 什么是反向代理 正向代理 反向代理: 反向代理服务器决定哪台服务器提供服务. 返回代理服务器不提供服务器.也是请求的转发. 反向代理(Reverse Proxy)方式是指以代理服务器来接受Int ...

  10. 转:Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结

    转自:http://blog.csdn.net/business122/article/details/7536991 创建列表 sample_list = ['a',1,('a','b')] Pyt ...