题意:给出n个点,求最小包围圆。

解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久一直写不对……后来在计算几何的模板上找到了…………orz膜拜一下

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
const double eps = 1e-8;
int n;
struct point
{
double x, y;
}p[505];
bool dy(double x, double y)//x > y
{
return x > y + eps;
}
double disp2p(point a, point b)//两点距离
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
point l2l_inst_p(point u1, point u2, point v1, point v2)//两直线交点
{
point ans = u1;
double t = ((u1.x - v1.x) * (v1.y - v2.y) - (u1.y - v1.y) * (v1.x - v2.x)) /
((u1.x - u2.x) * (v1.y - v2.y) - (u1.y - u2.y) * (v1.x - v2.x));
ans.x += (u2.x - u1.x) * t;
ans.y += (u2.y - u1.y) * t;
return ans;
}
point circumcenter(point a, point b, point c)//三角形外接圆
{
point ua, ub, va, vb;
ua.x = (a.x + b.x) / 2;
ua.y = (a.y + b.y) / 2;
ub.x = ua.x - a.y + b.y;
ub.y = ua.y + a.x - b.x;
va.x = (a.x + c.x) / 2;
va.y = (a.y + c.y) / 2;
vb.x = va.x - a.y + c.y;
vb.y = va.y + a.x - c.x;
return l2l_inst_p(ua, ub, va, vb);
}
void min_cover_circle(point &c, double &r)//最小包围圆
{
random_shuffle(p, p + n);//貌似是随机排序用的……
c = p[0];
r = 0;
for(int i = 1; i < n; i++)
if(dy(disp2p(p[i], c), r))
{
c = p[i];
r = 0;
for(int k = 0; k < i; k++)
if(dy(disp2p(p[k], c), r))
{
c.x = (p[i].x + p[k].x) / 2;
c.y = (p[i].y + p[k].y) / 2;
r = disp2p(p[k], c);
for(int j = 0; j < k; j++)
if(dy(disp2p(p[j], c), r))
{
c = circumcenter(p[i], p[k], p[j]);
r = disp2p(p[i], c);
}
}
}
}
int main()
{
while(scanf("%d", &n) && n)
{
for(int i = 0; i < n; i++)
scanf("%lf%lf", &p[i].x, &p[i].y);
point c;
double r;
min_cover_circle(c, r);
printf("%.2lf %.2lf %.2lf\n", c.x, c.y, r);
}
return 0;
}

  

HDU 3007 Buried memory & ZOJ 1450 Minimal Circle的更多相关文章

  1. hdu 3007 Buried memory 最远点对

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007 Each person had do something foolish along with ...

  2. zoj 1450 Minimal Circle 最小覆盖圆

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450 You are to write a program to fi ...

  3. HDU 3007 Buried memory(计算几何の最小圆覆盖,模版题)

    Problem Description Each person had do something foolish along with his or her growth.But,when he or ...

  4. ZOJ 1450 Minimal Circle 最小圆覆盖

    套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...

  5. HDU - 3007 Buried memory

    传送门 最小圆覆盖模板. //Achen #include<algorithm> #include<iostream> #include<cstring> #inc ...

  6. 【HDOJ】3007 Buried memory

    1. 题目描述有n个点,求能覆盖这n个点的半径最小的圆的圆心及半径. 2. 基本思路算法模板http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066定义Di表示 ...

  7. HDU 3007 模拟退火算法

    Buried memory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. ZOJ1450 Minimal Circle

    You are to write a program to find a circle which covers a set of points and has the minimal area. T ...

  9. HDU 3007

    基本小圆覆盖模板题 #include <iostream> #include <algorithm> #include <cmath> using namespac ...

随机推荐

  1. ITaCS Change Password web part

    http://changepassword.codeplex.com/ A webpart is used to change your sharepoint AD password.

  2. iOS 支付宝应用(备用参考)

    1:先与支付宝签约,获得商户ID(partner)和账号ID(seller) 2:下载相应的公钥私钥文件(加密签名用) 3:下载支付宝SDK 4:生成订单信息5:调用支付宝客户端,由支付宝客户端跟支付 ...

  3. VC++创建、调用dll的方法步骤

    文章来源:http://www.cnblogs.com/houkai/archive/2013/06/05/3119513.html 代码复用是提高软件开发效率的重要途径.一般而言,只要某部分代码具有 ...

  4. 1020: [SHOI2008]安全的航线flight - BZOJ

    Description在设计航线的时候,安全是一个很重要的问题.首先,最重要的是应采取一切措施确保飞行不会发生任何事故,但同时也需要做好最坏的打算,一旦事故发生,就要确保乘客有尽量高的生还几率.当飞机 ...

  5. c++ deque 双端队列

    双端队列: 函数 描述 c.assign(beg,end)c.assign(n,elem)  将[beg; end)区间中的数据赋值给c.将n个elem的拷贝赋值给c. c.at(idx)  传回索引 ...

  6. 想要上市,SaaS 企业应该重点关注什么?(下)

    前言:那些非常期待能在纳斯达克敲钟的 SaaS 服务提供商们,希望能从已经上市的「前辈」身上学到一些东西.对企业的销售主管来说,他们控制着影响整个公司长期收益的多个因素,同时,他们也对潜在投资者和金融 ...

  7. 【疯狂Java讲义学习笔记】【数据类型与运算符】

    [学习笔记]1.8bit = 1byte,4byte = 1word.Java中的整型数据有byte(1字节),short(2字节),int(4字节),long(8字节).Java中的浮点数据有flo ...

  8. 对Delphi控件作用的新理解(控件本身的源代码就是一个很强的工业级源码)

    最近几天,对Delphi控件的含义有了一个新的理解.其实它不仅仅是给程序员提供功能的一个表层调用,控件本身的源代码就是一个很强的工业级源码.而且它的Main例子,往往就已经是半成品.而别的语言里没有那 ...

  9. 使用xilinx的documentation navigator快速查找资料

    2013-06-22 14:56:39 documentation navigator是xilinx的资料导航,是一个小插件,可以到xilinx的官网上下载,我的是Xilinx_DocNav_2013 ...

  10. haproxy 规则匹配到了就停止,不会继续匹配下一个

    acl url_web_wwm path_beg -i /scan use_backend zjtest7_com if url_web_wwm acl url_static path_end .ht ...