HDU3932

题目大意:给定一堆点,找到一个点的位置使这个点到所有点中的最大距离最小

简单的模拟退火即可

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm> using namespace std; #define N 1005
#define PI acos(-1.0)
#define random(x) (rand()%x+1)
const int P = ;
const int L = ;
double X,Y;
int n;
double mindis[N]; struct Point{
double x , y;
Point(double x= , double y=):x(x),y(y){}
void input(){
scanf("%lf%lf" , &x , &y);
}
}p[N] , tmp[N]; double dis(Point a , Point b)
{
double x = a.x-b.x , y=a.y-b.y;
return sqrt(x*x+y*y);
} double cal(Point a)
{
double maxn = ;
for(int i= ; i<n ; i++) maxn = max(maxn , dis(a , p[i]));
return maxn;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("a.in" , "r" , stdin);
#endif // ONLINE_JUDGE
while(~scanf("%lf%lf%d" , &X , &Y , &n))
{
for(int i= ; i<n ; i++) p[i].input();
for(int i= ; i<P ; i++){
tmp[i].x = random()/1000.0*X;
tmp[i].y = random()/1000.0*Y;
mindis[i] = cal(tmp[i]);
}
double step = sqrt(X*X+Y*Y)/;
while(step>1e-){
for(int i= ; i<P ; i++){
for(int j= ; j<L ; j++){
Point cur;
double ang = random()/1000.0**PI;
cur.x = tmp[i].x+cos(ang)*step;
cur.y = tmp[i].y+sin(ang)*step;
if(cur.x< || cur.x>X || cur.y< || cur.y>Y) continue;
double val = cal(cur);
if(val<mindis[i]){
mindis[i] = val;
tmp[i] = cur;
}
}
}
step *= 0.85;
}
double ret = 1e20;
Point u;
for(int i= ; i<P ; i++){
if(mindis[i]<ret){
u = tmp[i];
ret = mindis[i];
}
}
printf("(%.1f,%.1f).\n%.1f\n" , u.x,u.y,ret);
}
return ;
}

HDU 3932 模拟退火的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. HDU 3932

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

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

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

  8. hdu 5017 模拟退火算法

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

  9. hdu 5017 模拟退火

    题意:给出椭球面的立体解析式,要求椭球面上距离原点最近的点的距离 sol:这题要想推公式就

随机推荐

  1. [未读]backbonejs应用程序开发

    买来就没有动过,那阵子刚好离职找工作,之后学backbone的劲头就过去了= =

  2. [转]如何使用MFC和类型库创建自动化项目

    本文转自:http://www.cnblogs.com/zhoug2020/archive/2012/04/01/2429064.html 摘要 本文详细介绍了如何自动化像Microsoft Offi ...

  3. [BZOJ1053][SDOI2005]反素数ant 数学

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1053 假设这个最大的反素数为$x$,那么$1<p<x$中数的因子数都没有$x$ ...

  4. 【HEVC帧间预测论文】P1.1 基于运动特征的HEVC快速帧间预测算法

    基于运动特征的 HEVC 快速帧间预测算法/Fast Inter-Frame Prediction Algorithm for HEVC Based on Motion Features <HE ...

  5. Java 利用FTP上传,下载文件,遍历文件目录

    Java实现FTP上传下载文件的工具包有很多,这里我采用Java自带的API,实现FTP上传下载文件.另外JDK1.7以前的版本与其之后版本的API有了较大的改变了. 例如: JDK1.7之前 JDK ...

  6. Python Linked List

    上周日教导一个科班非技术的朋友学习 Python 编程.他的 Python 水平大概就是看了几篇短的 Python 介绍博客.会流程控制和全局函数编写. 具体教导思路是从自己实现一个链表出发,研究学习 ...

  7. uva1613 K-Graph Oddity

    题目要求k>=最大度数:观察,颜色数量和度数的关系,得颜色数=最大度数+1(偶数)//最大度数(奇数) 可以满足染色关系一个点和周围的点的颜色数加起来最大为它的度数+1: k=所有点中最大的度. ...

  8. 【整理】 vue-cli 打包后显示favicon.ico小图标

    vue-cli 打包后显示favicon.ico小图标 https://www.cnblogs.com/mmzuo-798/p/9285013.html

  9. django 模板中{%for%}的使用

    1.{%for athlete in list reversed%}  reversed用于反向迭代 2.for 标签 支持一个可选的 empty 变量 3.forloop 模板变量 4.forloo ...

  10. 关于Error:Maven Resources Compiler: Maven project configuration required for module '项目名' isn't available. Compilation of Maven projects is supported only&

    总是出现Error:Maven Resources Compiler: Maven project configuration required for module '项目名' isn't avai ...