HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出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的更多相关文章
- hdu 3007 Buried memory 最远点对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007 Each person had do something foolish along with ...
- zoj 1450 Minimal Circle 最小覆盖圆
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450 You are to write a program to fi ...
- HDU 3007 Buried memory(计算几何の最小圆覆盖,模版题)
Problem Description Each person had do something foolish along with his or her growth.But,when he or ...
- ZOJ 1450 Minimal Circle 最小圆覆盖
套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...
- HDU - 3007 Buried memory
传送门 最小圆覆盖模板. //Achen #include<algorithm> #include<iostream> #include<cstring> #inc ...
- 【HDOJ】3007 Buried memory
1. 题目描述有n个点,求能覆盖这n个点的半径最小的圆的圆心及半径. 2. 基本思路算法模板http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066定义Di表示 ...
- HDU 3007 模拟退火算法
Buried memory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 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 ...
- HDU 3007
基本小圆覆盖模板题 #include <iostream> #include <algorithm> #include <cmath> using namespac ...
随机推荐
- python 练习题
python是一个功能很强大的语言,他可以解决各种在数学问题,下面我分享一些练习题供大家参考: 有关正态分布的问题: # -*- coding: cp936 -*- import math a=0 u ...
- sql之表的表达式
1.派生表 实质:就是特殊的子查询(将查询结果放在from后面) 含有一张Order表: 看下面的sql语句: select orderid,orderdate,custid from ( selec ...
- UIApplication深入研究
我们偶尔会调用这个类的api来实现一些功能,但是这个类是iOS编程中很重要的一个概念,所以总结以下这个类的信息,不对的地方请留言. UIApplication的核心作用是提供了iOS程序运行期间的控制 ...
- 1063: [Noi2008]道路设计 - BZOJ
Description Z 国坐落于遥远而又神奇的东方半岛上,在小Z 的统治时代公路成为这里主要的交通手段.Z 国共有n 座城市,一些城市之间由双向的公路所连接.非常神奇的是Z 国的每个城市所处的经度 ...
- 2001: [Hnoi2010]City 城市建设 - BZOJ
DescriptionPS国是一个拥有诸多城市的大国,国王Louis为城市的交通建设可谓绞尽脑汁.Louis可以在某些城市之间修建道路,在不同的城市之间修建道路需要不同的花费.Louis希望建造最少的 ...
- jQuery中的join方法
和JS 中的JOIN 方法一样,将一数组按照JOIN的参数连接起来.比如: var arr = [ "a", "b", "c", " ...
- notepad++ 开启/关闭 记住最后打开的文件
开启记住最后打开的文件 1) 6.3以前版本如下设置: 设置-->首选项-->其他 把左下角的 "记住最后打开文件" 勾选. 2) 6.3以后版本如下设置: 设置--& ...
- VIM的高级使用
VIM的高级使用 转:http://www.cnblogs.com/itech/archive/2012/02/22/2363111.html 1)一些常用的Vim配置,在~/.vimrc中 syn ...
- ASC #1
开始套题训练,第一套ASC题目,记住不放过每一题,多独立思考. Problem A ZOJ 2313 Chinese Girls' Amusement 循环节 题意:给定n,为圆环长度,求k < ...
- rand5()产生rand7()
http://www.cnblogs.com/dwdxdy/archive/2012/07/28/2613135.html 利用rand5()产生rand7().rand5()产生1到5的整数,ran ...