HDU 3932 Groundhog Build Home 【基础模拟退火】
和刚才那道是一模一样
不过求的是最小的,只要稍微修改一下就可以了~
//#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 = ;//
for(int i = ; i < n; ++i)
ans = max(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));
while(EOF != 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("(%.1f,%.1f).\n",tp[idx].x,tp[idx].y);
printf("%.1f\n",best[idx]);
}
return ;
}
HDU 3932 Groundhog Build Home 【基础模拟退火】的更多相关文章
- hdu 3932 Groundhog Build Home
Groundhog Build Home Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- hdu 3932 Groundhog Build Home —— 模拟退火
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3932 找一个位置使距离最远的点的距离最小: 上模拟退火: 每次向距离最远的点移动,注意判断一下距离最远的点 ...
- hdu 3932 Groundhog Build Home——模拟退火
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3932 注意平均值与最远的点距离为0的情况.所以初值设成-1,这样 id 就不会乱.不过设成0也可以.注意判 ...
- hdu 2215 & hdu 3932(最小覆盖圆)
Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Groundhog Build Home - HDU - 3932(模拟退火)
题意 给定一个矩形内的\(n\)个点,在矩形中找一个点,离其他点的最大距离最小. 题解 模拟退火. 这个题需要\(x\)和\(y\)坐标随机动的时候多随机几次.否则就WA了.另外由于随机多次,如果温度 ...
- HDU 3932 模拟退火
HDU3932 题目大意:给定一堆点,找到一个点的位置使这个点到所有点中的最大距离最小 简单的模拟退火即可 #include <iostream> #include <cstdio& ...
- HDU 3932
http://acm.hdu.edu.cn/showproblem.php?pid=3932 一定范围的平面上给一些点,求到这些点的最大距离最小,和上一题的题意正好相反,稍微改一下就可以 这个问题又叫 ...
- POJ 1379 Run Away 【基础模拟退火】
题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...
- hdu 1711 Number Sequence KMP 基础题
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- web 性能优化指南阅读笔记
1.关于拥塞预防算法 PRR-比例降速,RFC6937 规定的一个新算法,其目标是改进丢包后的恢复速度,谷歌测量结果:该算法改进丢包造成的平均连接延迟减少了3%-10%.PRR是linux 3.2+内 ...
- AngularJS Factory Service Provider
先看看http://www.cnblogs.com/mbydzyr/p/3460501.html http://www.oschina.net/translate/angularjs-factory- ...
- Bootstrap Collapse使用
参考 http://wrongwaycn.github.io/bootstrap/docs/javascript.html#collapse http://www.w3resource.com/twi ...
- 帝国cms灵动标签下常用标签
这里简单整理下灵动标签下的常用标签 标题名称:<?=$bqr['title']?> <?=esub($bqr[title],22)?> 限制字符22个 标题链接:<?= ...
- Splunk
http://www.huxiu.com/article/33724/1.html http://www.netis.com.cn/splunk/%E4%BB%80%E4%B9%88%E6%98%AF ...
- SSH 配置日记
1 注意struts2-spring-plugin.jar的导入. Unable to load configuration. - action 异常.需要导入这个包 2 很久都跑不通的 ...
- robomongo
Robomongo 是一个可视化的mongodb数据库工具,提供对mongodb的操作,javascript执行及语法高亮提示. 安装教程
- 七、cocos2dx之粒子系统
本文由qinning199原创,转载请注明:http://www.cocos2dx.net/?p=66 一.介绍 粒子系统指的是一个使用大量很小的精灵或者其他的一些绘制对象模拟一些模糊效果.使用传统的 ...
- C++ 函数映射使用讲解
想想我们在遇到多语句分支时是不是首先想到的是 switc case 和 if else if ... 这2种方式在编码方面确实简单少,但是当分支达到一定数量后,特别是分支内部有嵌套大段代码或者再嵌套分 ...
- js如何判断一个对象是不是Array?(转载)
js如何判断一个对象是不是Array? 在开发中,我们经常需要判断某个对象是否为数组类型,在Js中检测对象类型的常见方法都有哪些呢? typeof 操作符 对于Function, String, Nu ...