题目:http://acm.hdu.edu.cn/showproblem.php?pid=3932

找一个位置使距离最远的点的距离最小;

上模拟退火;

每次向距离最远的点移动,注意判断一下距离最远的点距离为0的情况。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<ctime>
#define eps 1e-15
#define dc 0.99
using namespace std;
typedef double db;
int const xn=;
int n,xx[xn],yy[xn],rx,ry;
db ansx,ansy,ans;
db dist(db x,db y,db a,db b){return sqrt((x-a)*(x-a)+(y-b)*(y-b));}
void SA()
{
db T=,x=ansx/n,y=ansy/n,tx,ty; int id;
ans=1e9;
while(T>eps)
{
db ret=-,k;
for(int i=;i<=n;i++)
if(ret<(k=dist(x,y,xx[i],yy[i])))id=i,ret=k;
if(ret!=-&&ret<ans)ans=ret,ansx=x,ansy=y;
x+=(xx[id]-x)/ret*T;
y+=(yy[id]-y)/ret*T;
T*=dc;
}
}
int main()
{
srand(time());
while(~scanf("%d%d%d",&rx,&ry,&n))
{
ansx=; ansy=;
for(int i=;i<=n;i++)
scanf("%d%d",&xx[i],&yy[i]),ansx+=xx[i],ansy+=yy[i];
SA();
printf("(%.1lf,%.1lf).\n%.1lf\n",ansx,ansy,ans);
}
return ;
}

hdu 3932 Groundhog Build Home —— 模拟退火的更多相关文章

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

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

  2. hdu 3932 Groundhog Build Home

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

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

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

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

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

  5. Groundhog Build Home - HDU - 3932(模拟退火)

    题意 给定一个矩形内的\(n\)个点,在矩形中找一个点,离其他点的最大距离最小. 题解 模拟退火. 这个题需要\(x\)和\(y\)坐标随机动的时候多随机几次.否则就WA了.另外由于随机多次,如果温度 ...

  6. HDU 3932 模拟退火

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

  7. HDU 3932

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

  8. 【2017 Multi-University Training Contest - Team 7 && hdu 6121】Build a tree

    [链接]点击打开链接 [题意] 询问n个点的完全k叉树,所有子树节点个数的异或总和为多少. [题解] 考虑如下的一棵k=3叉树,假设这棵树恰好有n个节点. 因为满的k叉树,第i层的节点个数为k^(i- ...

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

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

随机推荐

  1. 【Nginx】开发一个HTTP过滤模块

    与HTTP处理模块不同.HTTP过滤模块的工作是对发送给用户的HTTP响应做一些加工. server返回的一个响应能够被随意多个HTTP过滤模块以流水线的方式依次处理.HTTP响应分为头部和包体,ng ...

  2. 阿里巴巴为什么主推HSF?比Dubbo有哪些优势?

    作者:匿名用户链接:https://www.zhihu.com/question/39560697/answer/187538165来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...

  3. Git以及github的使用方法(五),暂存区和工作区

    Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 先来看名词解释. 工作区(Working Directory) 就是你在电脑里能看到的目录,比如我的learngit文件夹就是一个工 ...

  4. sql导入数据库

    有问题可以尝试加上这句 DROP TABLE IF EXISTS `t_saler_login_log`;

  5. linux中断子系统:中断号的映射与维护初始化mmap过程

    本文均属自己阅读源代码的点滴总结.转账请注明出处谢谢. 欢迎和大家交流.qq:1037701636 email:gzzaigcn2009@163.com 写在前沿: 好久好久没有静下心来整理一些东西了 ...

  6. Google Chrome浏览器之删除Goolge搜索结果重定向插件Remove Google Redirects

    https://chrome.google.com/webstore/detail/remove-google-redirects/ccenmflbeofaceccfhhggbagkblihpoh?h ...

  7. selenium之 chromedriver与chrome版本映射表(更新至v2.29)

    最新的chromedriver与chrome的对应关系表: chromedriver版本 支持的Chrome版本 v2.37 v64-66 v2.36 v63-65 v2.35 v62-64 v2.3 ...

  8. Matlab中图片保存的四种方法

    matlab的绘图和可视化能力是不用多说的,可以说在业内是家喻户晓的.Matlab提供了丰富的绘图函数,比如ez**系类的简易绘图函数,surf.mesh系类的数值绘图函数等几十个.另外其他专业工具箱 ...

  9. Lance老师UI系列教程第九课->高仿比特币监控大师

    http://blog.csdn.net/lancees/article/details/22898971

  10. 【WordSearch】Word Search

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...