题意:给出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. EXTJS 4.2 资料 控件之combo 联动

    写两个数据源: 1.IM_ST_Module.js { success:true, data:[ { ModuleId: '1', ModuleName: '资讯' } , { ModuleId: ' ...

  2. 【POJ2104】kth num

    You are working for Macrohard company in data structures department. After failing your previous tas ...

  3. iOS9下修改回HTTP模式进行网络请求

    升级为iOS9后,默认请求类型为https,如何使用http进行请求会报错 The resource could not be loaded because the App Transport Sec ...

  4. scrum敏捷开发

    团队PM:袁佩佩 scrum敏捷开发计划制定: 确定项目实施具体阶段目标 确定项目相关任务分解 确定每日站立会议进行计划 确定项目计划总结日程 确定风险解决方案

  5. Dialog控件

    代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--& ...

  6. #pragma预处理指令讲解

    在所有的预处理指令中,#Pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#pragma指令对每个编译器给出了一个方法,在保持与C和C++语言完全兼容的 ...

  7. hdu 4681

    将c串从a,b串中删去后求最长公子列  直接暴会超时 #include <cstdio> #include <cstdlib> #include <algorithm&g ...

  8. URAL 1012 K-based Numbers. Version 2(DP+高精度)

    题目链接 题意 :与1009一样,不过这个题的数据范围变大. 思路:因为数据范围变大,所以要用大数模拟,用java也行,大数模拟也没什么不过变成二维再做就行了呗.当然也可以先把所有的都进行打表,不过要 ...

  9. [博弈]ZOJ3591 Nim

    题意: 给了一串数,个数不超过$10^5$,这串数是通过题目给的一段代码来生成的 int g = S; ; i<N; i++) { a[i] = g; ) { a[i] = g = W; } = ...

  10. 垃圾收集器GC的种类

    堆内存的结构: