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

相关题型连接:

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

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450

Buried memory

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2368    Accepted Submission(s): 1291
Problem Description
Each person had do something foolish along with his or her growth.But,when he or she did this that time,they could not predict that this thing is a mistake and they will want this thing would rather not happened.
The world king Sconbin is not the exception.One day,Sconbin was sleeping,then swakened by one nightmare.It turned out that his love letters to Dufein were made public in his dream.These foolish letters might ruin his throne.Sconbin decided to destroy the letters by the military exercises's opportunity.The missile is the best weapon.Considered the execution of the missile,Sconbin chose to use one missile with the minimum destruction.
Sconbin had writen N letters to Dufein, she buried these letters on different places.Sconbin got the places by difficult,he wants to know where is the best place launch the missile,and the smallest radius of the burst area. Let's help Sconbin to get the award.
Input
There are many test cases.Each case consists of a positive integer N(N<500,^V^,our great king might be a considerate lover) on a line followed by N lines giving the coordinates of N letters.Each coordinates have two numbers,x coordinate and y coordinate.N=0 is the end of the input file.
Output
For each case,there should be a single line in the output,containing three numbers,the first and second are x and y coordinates of the missile to launch,the third is the smallest radius the missile need to destroy all N letters.All output numbers are rounded to the second digit after the decimal point.
Sample Input
3 1.00 1.00 2.00 2.00 3.00 3.00 0
Sample Output
2.00 2.00 1.41

方法一:随机增量法:

分析:用最小的圆覆盖住所有的点:随机增量法复杂度是O(n);

2、算法及原理算法介绍:我们本次算法的设计是基于这样一个简单直观的性质:

在既定的给定点条件下,如果引入一张新的半平面,只要此前的最优解顶点(即唯一确定最小包围圆的几个关键顶点)能够包含于其中,则不必对此最优解进行修改,亦即此亦为新点集的最优解;否则,新的最优解顶点必然位于这个新的半空间的边界上。定理可以通过反证法证明。于是,基于此性质,我们便可得到一个类似于线性规划算法的随机增量式算法。定义Di为相对于pi的最小包围圆。此算法实现的关键在于对于pi∉Di-1时的处理。显然,如果pi∈Di-1,则Di= Di-1;否则,需要对Di另外更新。而且,Di的组成必然包含了pi;因此,此种情况下的最小包围圆是过pi点且覆盖点集{ p1 ,p2 ,p3 ……pi-1}的最小包围圆。则仿照上述处理的思路,Di={ p1 ,pi },逐个判断点集{ p2 ,p3 ……pi-1 },如果存在pj∉ Di,则Di={pj,pi }。同时,再依次对点集{ p1 ,p2 ,p3 ……pj-1 }判断是否满足pk∈Di,若有不满足,则Di={pk ,pj,pi }。由于,三点唯一地确定一个圆,故而,只需在此基础上判断其他的点是否位于此包围圆内,不停地更新pk。当最内层循环完成时,退出循环,转而更新pj;当次内层循环结束时,退出循环,更新pi。当i=n时,表明对所有的顶点均已处理过 ,此时的Dn即表示覆盖了给定n个点的最小包围圆。

总结:

假设圆O是前i-1个点得最小覆盖圆,加入第i个点,如果在圆内或边上则什么也不做。否,新得到的最小覆盖圆肯定经过第i个点。然后以第i个点为基础(半径为0),重复以上过程依次加入第j个点,若第j个点在圆外,则最小覆盖圆必经过第j个点。重复以上步骤(因为最多需要三个点来确定这个最小覆盖圆,所以重复三次)。遍历完所有点之后,所得到的圆就是覆盖所有点得最小圆。证明可以考虑这么做:最小圆必定是可以通过不断放大半径,直到所有以任意点为圆心,半径为半径的圆存在交点,此时的半径就是最小圆。所以上述定理可以通过这个思想得到。这个做法复杂度是O(n)的,当加入圆的顺序随机时,因为三点定一圆,所以不在圆内概率是3/i,求出期望可得是O(n)。

方法二:模拟退火法:对于每个枚举的点找到改点到所给点的最远点的距离,然后保证这个距离最小,即为所求圆的半径;

程序:

方法一:随机增量法:

#include"string.h"
#include"stdio.h"
#include"queue"
#include"stack"
#include"vector"
#include"algorithm"
#include"iostream"
#include"math.h"
#include"stdlib.h"
#define M 522
#define inf 100000000
#define eps 1e-8
#define PI acos(-1.0)
using namespace std;
double X,Y;
struct Point
{double x,y;
}p[M];
struct Triangle
{Point v[3];
};
struct Circle
{Point center;double r;
};
double pow(double x)
{return x*x;
}
double Len(Point a,Point b)
{return sqrt(pow(a.x-b.x)+pow(a.y-b.y));
}
double TriangleArea(Triangle a)//求三角形的面积
{double px1=a.v[1].x-a.v[0].x;double py1=a.v[1].y-a.v[0].y;double px2=a.v[2].x-a.v[0].x;double py2=a.v[2].y-a.v[0].y;return fabs(px1*py2-px2*py1)/2;
}
Circle CircleOfTriangle(Triangle t)//就三角形外接圆
{Circle tmp;double a=Len(t.v[0],t.v[1]);double b=Len(t.v[0],t.v[2]);double c=Len(t.v[1],t.v[2]);tmp.r=a*b*c/4/TriangleArea(t);double a1=t.v[1].x-t.v[0].x;double b1=t.v[1].y-t.v[0].y;double c1=(a1*a1+b1*b1)/2;double a2=t.v[2].x-t.v[0].x;double b2=t.v[2].y-t.v[0].y;double c2=(a2*a2+b2*b2)/2;double d=a1*b2-a2*b1;tmp.center.x=t.v[0].x+(c1*b2-c2*b1)/d;tmp.center.y=t.v[0].y+(a1*c2-a2*c1)/d;return tmp;
}
void Run(int n)
{random_shuffle(p+1,p+n+1);//随机排序取点int i,j,k;Circle tep;tep.center=p[1];tep.r=0;for(i=2;i<=n;i++){if(Len(p[i],tep.center)>tep.r+eps){tep.center=p[i];tep.r=0;for(j=1;j<i;j++){if(Len(p[j],tep.center)>tep.r+eps){tep.center.x=(p[i].x+p[j].x)/2;tep.center.y=(p[i].y+p[j].y)/2;tep.r=Len(p[i],p[j])/2;for(k=1;k<j;k++){if(Len(p[k],tep.center)>tep.r+eps){Triangle t;t.v[0]=p[i];t.v[1]=p[j];t.v[2]=p[k];tep=CircleOfTriangle(t);}}}}}}printf("%.2lf %.2lf %.2lf\n",tep.center.x,tep.center.y,tep.r);
}
int main()
{int n,i;while(scanf("%d",&n),n){for(i=1;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);Run(n);}
}

方法二:模拟退火法:(hdu3932)

#include"string.h"
#include"stdio.h"
#include"queue"
#include"stack"
#include"vector"
#include"algorithm"
#include"iostream"
#include"math.h"
#include"stdlib.h"
#define M 1009
#define inf 100000000
#define eps 1e-8
#define PI acos(-1.0)
using namespace std;
double X,Y;
int n;
struct Point
{double x,y,dis;Point(){}Point(double xx,double yy){x=xx;y=yy;}bool check(){if(x>0&&y>0&&x<X&&y<Y)return true;return false;}
}p[M],q[50];
double pow(double x)
{return x*x;
}
double Len(Point a,Point b)
{return sqrt(pow(a.x-b.x)+pow(a.y-b.y));
}
double fun(Point a)
{double maxi=0;for(int i=1;i<=n;i++){double L=Len(a,p[i]);if(maxi<L)maxi=L;}return maxi;
}
int main()
{int i;while(scanf("%lf%lf%d",&X,&Y,&n)!=EOF){for(i=1;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);int po=15,est=15;for(int i=1;i<=po;i++){q[i].x=(rand()%1000+1)/1000.0*X;q[i].y=(rand()%1000+1)/1000.0*Y;q[i].dis=fun(q[i]);}double temp=max(X,Y);while(temp>0.001){for(int i=1;i<=po;i++){for(int j=1;j<=est;j++){double rad=(rand()%1000+1)/1000.0*PI*2;Point cur;cur.x=q[i].x+temp*cos(rad);cur.y=q[i].y+temp*sin(rad);if(!cur.check())continue;cur.dis=fun(cur);if(cur.dis<q[i].dis)q[i]=cur;}}temp*=0.8;}int id=1;for(int i=1;i<=po;i++)if(q[id].dis>q[i].dis)id=i;printf("(%.1lf,%.1lf).\n%.1lf\n",q[id].x,q[id].y,q[id].dis);}return 0;
}

转载于:https://www.cnblogs.com/mypsq/p/4348151.html

最小圆覆盖(随机增量法模拟退火法)相关推荐

  1. matlab模拟退火最小球覆盖,最小圆覆盖最小球覆盖 (增量法和模拟退火法)

    这种题几乎一套板子走天下. 昨天做最小圆覆盖用的都是增量法,压根没看过退火模拟法,因为退火模拟法并不是很稳定.今天看最小球覆盖时发现用到了退火模拟法,于是看了看最小圆覆盖的退火模拟法,用退火板子提交直 ...

  2. 随机增量法:bzoj 1336 bzoj 1337 最小圆覆盖

    1337: 最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 1170  Solved: 573 [Submit][Status][Discus ...

  3. ZOJ - 1450 Minimal Circle HDU - 3007 Buried memory 最小圆覆盖模板 【随机函数】【增量法】

    题意 给N个点,求最小的圆将这N个点全部覆盖,输出圆心坐标和半径 分析 最小的圆肯定落在三个点上,因此暴力枚举圆上的三个点即可,点增量算法O(n ^ 3),加入随机化,平均复杂度可以降到O(n^2) ...

  4. BZOJ 3564: [SHOI2014]信号增幅仪(随机增量法)

    如果是个圆的话好办,如果是拉成椭圆呢?直接压回去!!! 然后随机增量法就行了 CODE: #include<cstdio> #include<iostream> #includ ...

  5. NO.79——BFS,DFS,Astar,爬山法,最抖爬山法,模拟退火法解决八数码问题Python实现

    问题描述 无非就是将无序数列变成有序数列. 之间写过关于这个问题的解决办法,但是当时对各种算法理解的不是很透彻,比如广度优先算法和深度优先算法,同样都是维护一个open表,怎么用列表实现队列和栈的操作 ...

  6. matlab模拟退火最小球覆盖,【模板】模拟退火 费马点以及最小球覆盖

    最近学了一波模拟退火.个人感觉,就是随机算法,然后我们的目标点,一开始温度T高的时候会移动的剧烈,T小的时候移动的缓和(所以这就是为什么每一次移动的距离都是乘T).然后真正的模拟退火是如果当前的tem ...

  7. [学习笔记]最小圆覆盖

    随机增量算法 图片来自:我 1.random_shuffle 2.枚举增量:点i 圆 C; for(i=1 to n) {if(P[i] 不在 C 内){C = {P[i], 0};for(j=1 t ...

  8. luoguP1742 最小圆覆盖

    最小圆覆盖 首先 没错,我是个蒟蒻.luogu 流程 圆 C; for(i=1 to n) {if(P[i] 不在 C 内) {C = {P[i], 0};for(j=1 to i-1) {if(P[ ...

  9. POJ 2069最小球覆盖 HDU3007最小圆覆盖【模拟淬火算法】

    POJ 2069最小球覆盖 1.给定N个三维点,要求覆盖这些点的最小球半径: 2.采用模拟淬火算法,随机选取一个点作为初始解,然后不断向当前最远的点靠近: 3.这是一个不断调整的过程,对应模拟淬火算法 ...

  10. P1742 最小圆覆盖

    P1742 最小圆覆盖 题意: 给出N个点,让你画一个最小的包含所有点的圆. 题解: 先说结论: 最优解的圆一定是在以某两个点连线为直径的圆 或者 某三个点组成的三角形的外接圆 初始化将某个圆心定为第 ...

最新文章

  1. Pycharm问题归纳
  2. php 过滤微信符号昵称,PHP方法处理微信昵称特殊符号过滤
  3. Angularjs进阶笔记(2)—自定义指令中的数据绑定
  4. php descryptoserviceprovider,[WPF]C#和php实现DES加密和解密
  5. 1亿中国人已被AI批改过作业
  6. Ubuntu下安装VirtualBox和Android 安装到虚拟机中
  7. jsp和java一样具有平台独立性._web开发技术总复习题
  8. OAI LTE系统搭建 -- OAI EPC
  9. 畅捷通T+任意文件上传(CNVD-2022-60632 )漏洞复现
  10. Java数组索引越界异常
  11. Reflex WMS入门系列七:收货(Receipt)
  12. 基于单片机的音乐盒系统设计(#0435)
  13. 【UE】初识Slate编辑器-理解一个最基础的编辑器界面
  14. 达内CEO受邀出席搜狐“2011职业教育高峰论坛”
  15. Nginx下的反向代理 双层代理 负载均衡
  16. matlab2016 dll,VS2012Matlab2016b dll文件混合编
  17. 角度前方交会点坐标计算完整步骤
  18. 一点击文件夹里的wps文件就卡死,不管放在哪个盘
  19. 艾美捷胆固醇肉豆蔻酸酯说明书和相关研究
  20. 浅谈OpenNI之我见

热门文章

  1. 块状元素(div)与内联元素(span)
  2. IDEA 和 Eclipse 使用对比
  3. linux 笔记(2) 目录直接强行删除rm -rf *(删除当前目录所有的内容)
  4. 干货 | 彻底理解ANDROID BINDER通信架构(下)
  5. nginx开启密码认证
  6. VisualSVN-Server 安装以及使用教程
  7. Consul实践之Consul常见应用场景及方案梳理(FAQ)
  8. jQuery模拟页面加载进度条
  9. C语言的变量的作用域和生存期
  10. 刘长春:未来云时代——红帽开放混合云驱动增长