HDU 3932

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

一定范围的平面上给一些点,求到这些点的最大距离最小,和上一题的题意正好相反,稍微改一下就可以

这个问题又叫最小圆覆盖

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <ctime>
#include <cmath>
using namespace std ;
const double eps=1e-18 ;
int X,Y,M ;

struct point
{
    double x,y ;
    int OK()
    {
        if(x>-eps && x<X+eps && y>-eps && y<Y+eps)return 1 ;
        return 0 ;
    }
}p[1005],r[50] ;

double dis(point a,point b)
{
    return sqrt(pow(a.x-b.x,2)+pow(b.y-a.y,2)) ;
}

double ans[55] ;

int main()
{
    srand(time(NULL)) ;
    while(~scanf("%d%d%d",&X,&Y,&M))
    {
        for(int i=0 ;i<M ;i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y) ;
        }
        for(int i=0 ;i<20 ;i++)
        {
            r[i].x=(rand()%1000+1)/1000.0*X ;
            r[i].y=(rand()%1000+1)/1000.0*Y ;
            ans[i]=0.0 ;
            for(int j=0 ;j<M ;j++)
            {
                ans[i]=max(ans[i],dis(p[j],r[i])) ;
            }
        }
        double tmp=max(X,Y) ;
        while(tmp>0.01)
        {
            for(int i=0 ;i<20 ;i++)
            {
                point now=r[i],next ;
                for(int j=0 ;j<50 ;j++)
                {
                    double rad=(rand()%1000+1)/1000.0*2*3.1415926535 ;
                    next.x=now.x+cos(rad)*tmp ;
                    next.y=now.y+sin(rad)*tmp ;
                    if(!next.OK())continue ;
                    double m=0.0 ;
                    for(int k=0 ;k<M ;k++)
                        m=max(m,dis(p[k],next)) ;
                    if(m<ans[i])
                    {
                        ans[i]=m ;
                        r[i]=next ;
                    }
                }
            }
            tmp*=0.8 ;
        }
        double res=1e18 ;
        int idx ;
        for(int i=0 ;i<20 ;i++)
        {
            if(ans[i]<res)
            {
                res=ans[i] ;
                idx=i ;
            }
        }
        printf("(%.1lf,%.1lf).\n%.1lf\n",r[idx].x,r[idx].y,res) ;
    }
    return 0 ;
}

时间: 2024-08-01 19:20:19

HDU 3932的相关文章

hdu 3932 Groundhog Build Home —— 模拟退火

题目:http://acm.hdu.edu.cn/showproblem.php?pid=3932 找一个位置使距离最远的点的距离最小: 上模拟退火: 每次向距离最远的点移动,注意判断一下距离最远的点距离为0的情况. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<cstdlib&

hdu 3932 Groundhog Build Home

Groundhog Build Home Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2647    Accepted Submission(s): 1074 Problem Description Groundhogs are good at digging holes, their home is a hole, usually

平面点集的最小包围圆 hdu 3932

最小覆盖圆算法地址:http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066 平面点集的最小包围圆 1.           问题背景 考察固定在工作平台上的一直机械手,要捡起散落在不同位置的多个零件,并送到别的地方.那么,这只机械手的底座应该选在哪里呢?根据直觉,应该选在机械手需够着的那些位置的"中心".准确地讲,也就是包围这些点的那个最小圆的圆心----该位置的好处是,可使机械手的底座到它需要够着的那些点的最大距离最小化.于是可得如下问题:给

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>

HDU 3932 模拟退火

HDU3932 题目大意:给定一堆点,找到一个点的位置使这个点到所有点中的最大距离最小 简单的模拟退火即可 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <ctime> 7 #include <algorithm> 8 9 using name

HDU - 3932 Groundhog Build Home 模拟退火算法

Groundhogs are good at digging holes, their home is a hole, usually a group of groundhogs will find a more suitable area for their activities and build their home at this area .xiaomi has grown up, can no longer live with its parents.so it needs to b

计算几何及其应用——解析几何

写在前面:刚学专业课的时候,记得有天突发奇想,心说高三数学的压轴题能不能写个程序跑出答案,这样岂不是解放了数万苦逼高三生的双手?但是当时也仅仅是停留在想法上面,因为高中的解析几何虽然步骤程序化,但是有时候需要灵巧的因式分解,感觉以目前的编程水平还是写不出来,但是了解到数学有一个分支——计算几何,专门利用计算机来进行几何计算的一门科学,并且还与计算机图形学.计算机视觉和图像处理.机器人.计算机辅助设计和制造等高深学科有着联系(摘自<计算几何与应用>导言),所以今天怀着激动的心情开始了这个专题的学

覆盖点问题总结

1.最小的包围圆,将所有的点包围起来.(hdu 3932)最小覆盖圆算法地址:http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066 问题的背景提出:考察固定在工作平台上的一直机械手,要捡起散落在不同位置的多个零件,并送到别的地方.那么,这只机械手的底座应该选在哪里呢?根据直觉,应该选在机械手需够着的那些位置的"中心".准确地讲,也就是包围这些点的那个最小圆的圆心----该位置的好处是,可使机械手的底座到它需要够着的那些点的最大距离最小化.于是

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;