[hdu-3007]Buried memory 最小覆盖圆
大致题意:
平面上有n个点,求一个最小的圆覆盖住所有点
最小覆盖圆裸题
学习了一波最小覆盖圆算法
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<algorithm>
- #include<queue>
- #include<set>
- #include<map>
- #include<stack>
- #include<time.h>
- #include<cstdlib>
- #include<cmath>
- #include<list>
- using namespace std;
- #define MAXN 100100
- #define eps 1e-9
- #define For(i,a,b) for(int i=a;i<=b;i++)
- #define Fore(i,a,b) for(int i=a;i>=b;i--)
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define mkp make_pair
- #define pb push_back
- #define cr clear()
- #define sz size()
- #define met(a,b) memset(a,b,sizeof(a))
- #define iossy ios::sync_with_stdio(false)
- #define fre freopen
- #define pi acos(-1.0)
- #define inf 1e6+7
- #define Vector Point
- const int Mod=1e9+;
- typedef unsigned long long ull;
- typedef long long ll;
- int dcmp(double x){
- if(fabs(x)<=eps) return ;
- return x<?-:;
- }
- struct Point{
- double x,y;
- Point(double x=,double y=):x(x),y(y) {}
- bool operator < (const Point &a)const{
- if(x==a.x) return y<a.y;
- return x<a.x;
- }
- Point operator - (const Point &a)const{
- return Point(x-a.x,y-a.y);
- }
- Point operator + (const Point &a)const{
- return Point(x+a.x,y+a.y);
- }
- Point operator * (const double &a)const{
- return Point(x*a,y*a);
- }
- Point operator / (const double &a)const{
- return Point(x/a,y/a);
- }
- void read(){
- scanf("%lf%lf",&x,&y);
- }
- void out(){
- cout<<"debug: "<<x<<" "<<y<<endl;
- }
- bool operator == (const Point &a)const{
- return dcmp(x-a.x)== && dcmp(y-a.y)==;
- }
- };
- double Dot(Vector a,Vector b) {
- return a.x*b.x+a.y*b.y;
- }
- double dis(Vector a) {
- return sqrt(Dot(a,a));
- }
- double Cross(Point a,Point b){
- return a.x*b.y-a.y*b.x;
- }
- int n;
- Point p[];
- double r;
- Point cp;
- bool inCrcle(Point tp){
- return dcmp(dis(tp-cp)-r)<=;
- }
- void getCrcle(Point a,Point b,Point c){
- Point p1=b-a,p2=c-a;
- double d=*Cross(p1,p2);
- cp.x=(p2.y*Dot(p1,p1)-p1.y*Dot(p2,p2))/d+a.x;
- cp.y=(p1.x*Dot(p2,p2)-p2.x*Dot(p1,p1))/d+a.y;
- r=dis(a-cp);
- }
- void solve(){
- For(i,,n-) p[i].read();
- random_shuffle(p,p+n);
- cp=p[];r=;
- For(i,,n-) {
- if(!inCrcle(p[i])){
- r=;
- cp=p[i];
- For(j,,i-) {
- if(!inCrcle(p[j])) {
- r=dis(p[j]-p[i])/;
- cp=(p[j]+p[i])/;
- For(k,,j-) {
- if(!inCrcle(p[k]))
- getCrcle(p[i],p[j],p[k]);
- }
- }
- }
- }
- }
- printf("%.2lf %.2lf %.2lf\n",cp.x,cp.y,r);
- }
- int main(){
- // fre("in.txt","r",stdin);
- int t=;
- while(~scanf("%d",&n) && n) solve();
- return ;
- }
[hdu-3007]Buried memory 最小覆盖圆的更多相关文章
- hdu 3007 Buried memory 最远点对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007 Each person had do something foolish along with ...
- HDU 3007 Buried memory(计算几何の最小圆覆盖,模版题)
Problem Description Each person had do something foolish along with his or her growth.But,when he or ...
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- 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表示 ...
- Maple trees(最小覆盖圆)
Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- zoj 1450 Minimal Circle 最小覆盖圆
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450 You are to write a program to fi ...
- 最小圆覆盖 hdu 3007
今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...
- HDU 3007 模拟退火算法
Buried memory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- 读取txt内容放入set中
package pingbi; /** * 将txt文本读入导入到set中 * 问题: * 第一个地方有会多一个 ?--解决问题很简单,但不知道问题的原因 */ import java.io.Buff ...
- sublime 常用插件 感觉比较全了 够用了
插件介绍 Package Control 功能:安装包管理 简介:sublime插件控制台,提供添加.删除.禁用.查找插件等功能 使用:https://sublime.wbond.net/instal ...
- 最大公倍数_Greatest Common Divisor
计算最大公倍数 Static int gcd( int a, int b) { int t; while( b>0) { t = b; b = a % b; a = t; } return a; ...
- 快速排序Quick sort
快速排序Quick sort 原理,通过一趟扫描将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别进行快速排序,整个排序过程可以递归 ...
- 【lydsy1407】拓展欧几里得求解不定方程+同余方程
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1407 题意: 有n个野人,野人各自住在第c[i]个山洞中(山洞成环状),每年向前走p[i] ...
- 【BZOJ】1697: [Usaco2007 Feb]Cow Sorting牛排序
[算法]数学置换 [题意]给定n个数,要求通过若干次交换两个数的操作得到排序后的状态,每次交换代价为两数之和,求最小代价. [题解] 考虑置换的定义:置换就是把n个数做一个全排列. 从原数组到排序数组 ...
- 前端&后端程序员必备的Linux基础知识
一 从认识操作系统开始 1.1 操作系统简介 我通过以下四点介绍什么操作系统: 操作系统(Operation System,简称OS)是管理计算机硬件与软件资源的程序,是计算机系统的内核与基石: 操作 ...
- MSSQL 视图/事务(TRAN[SACTION])/存储过程(PROC[EDURE])/触发器(TRIGGER )
--视图 视图是一张虚拟表,它表示一张表的部分数据或多张表的综合数据,其结构和数据是建立在对表的查询基础上 视图在操作上和数据表没有什么区别,但两者的差异是其本质是不同: 数据表是实际存储记录的地方, ...
- js_一个简单的30分钟循环倒计时
吐槽段: 需求的变更是千变万化的,至少在你说服和你打交道的那位谁谁谁之前. 创业公司就是这样,产品经理一个想法,就是改改改,管你改起来复杂不复杂,在他们眼里都是非常简单的. 今天的一个小改动需求,把活 ...
- web-project 故障查看功能 检测是否启动fmd服务
def check_fmd_service(): try: output = subprocess.check_output('svcs -H -o state fmd',shell=True) st ...