大致题意:

  平面上有n个点,求一个最小的圆覆盖住所有点

  

  最小覆盖圆裸题

  学习了一波最小覆盖圆算法

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<queue>
  6. #include<set>
  7. #include<map>
  8. #include<stack>
  9. #include<time.h>
  10. #include<cstdlib>
  11. #include<cmath>
  12. #include<list>
  13. using namespace std;
  14. #define MAXN 100100
  15. #define eps 1e-9
  16. #define For(i,a,b) for(int i=a;i<=b;i++)
  17. #define Fore(i,a,b) for(int i=a;i>=b;i--)
  18. #define lson l,mid,rt<<1
  19. #define rson mid+1,r,rt<<1|1
  20. #define mkp make_pair
  21. #define pb push_back
  22. #define cr clear()
  23. #define sz size()
  24. #define met(a,b) memset(a,b,sizeof(a))
  25. #define iossy ios::sync_with_stdio(false)
  26. #define fre freopen
  27. #define pi acos(-1.0)
  28. #define inf 1e6+7
  29. #define Vector Point
  30. const int Mod=1e9+;
  31. typedef unsigned long long ull;
  32. typedef long long ll;
  33. int dcmp(double x){
  34. if(fabs(x)<=eps) return ;
  35. return x<?-:;
  36. }
  37. struct Point{
  38. double x,y;
  39. Point(double x=,double y=):x(x),y(y) {}
  40. bool operator < (const Point &a)const{
  41. if(x==a.x) return y<a.y;
  42. return x<a.x;
  43. }
  44. Point operator - (const Point &a)const{
  45. return Point(x-a.x,y-a.y);
  46. }
  47. Point operator + (const Point &a)const{
  48. return Point(x+a.x,y+a.y);
  49. }
  50. Point operator * (const double &a)const{
  51. return Point(x*a,y*a);
  52. }
  53. Point operator / (const double &a)const{
  54. return Point(x/a,y/a);
  55. }
  56. void read(){
  57. scanf("%lf%lf",&x,&y);
  58. }
  59. void out(){
  60. cout<<"debug: "<<x<<" "<<y<<endl;
  61. }
  62. bool operator == (const Point &a)const{
  63. return dcmp(x-a.x)== && dcmp(y-a.y)==;
  64. }
  65. };
  66. double Dot(Vector a,Vector b) {
  67. return a.x*b.x+a.y*b.y;
  68. }
  69. double dis(Vector a) {
  70. return sqrt(Dot(a,a));
  71. }
  72. double Cross(Point a,Point b){
  73. return a.x*b.y-a.y*b.x;
  74. }
  75. int n;
  76. Point p[];
  77. double r;
  78. Point cp;
  79. bool inCrcle(Point tp){
  80. return dcmp(dis(tp-cp)-r)<=;
  81. }
  82. void getCrcle(Point a,Point b,Point c){
  83. Point p1=b-a,p2=c-a;
  84. double d=*Cross(p1,p2);
  85. cp.x=(p2.y*Dot(p1,p1)-p1.y*Dot(p2,p2))/d+a.x;
  86. cp.y=(p1.x*Dot(p2,p2)-p2.x*Dot(p1,p1))/d+a.y;
  87. r=dis(a-cp);
  88. }
  89. void solve(){
  90. For(i,,n-) p[i].read();
  91. random_shuffle(p,p+n);
  92. cp=p[];r=;
  93. For(i,,n-) {
  94. if(!inCrcle(p[i])){
  95. r=;
  96. cp=p[i];
  97. For(j,,i-) {
  98. if(!inCrcle(p[j])) {
  99. r=dis(p[j]-p[i])/;
  100. cp=(p[j]+p[i])/;
  101. For(k,,j-) {
  102. if(!inCrcle(p[k]))
  103. getCrcle(p[i],p[j],p[k]);
  104. }
  105. }
  106. }
  107. }
  108. }
  109. printf("%.2lf %.2lf %.2lf\n",cp.x,cp.y,r);
  110. }
  111. int main(){
  112. // fre("in.txt","r",stdin);
  113. int t=;
  114. while(~scanf("%d",&n) && n) solve();
  115. return ;
  116. }

[hdu-3007]Buried memory 最小覆盖圆的更多相关文章

  1. hdu 3007 Buried memory 最远点对

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

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

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

  3. HDU 3007 Buried memory & ZOJ 1450 Minimal Circle

    题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...

  4. HDU - 3007 Buried memory

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

  5. 【HDOJ】3007 Buried memory

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

  6. Maple trees(最小覆盖圆)

    Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  7. zoj 1450 Minimal Circle 最小覆盖圆

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

  8. 最小圆覆盖 hdu 3007

    今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...

  9. HDU 3007 模拟退火算法

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

随机推荐

  1. 读取txt内容放入set中

    package pingbi; /** * 将txt文本读入导入到set中 * 问题: * 第一个地方有会多一个 ?--解决问题很简单,但不知道问题的原因 */ import java.io.Buff ...

  2. sublime 常用插件 感觉比较全了 够用了

    插件介绍 Package Control 功能:安装包管理 简介:sublime插件控制台,提供添加.删除.禁用.查找插件等功能 使用:https://sublime.wbond.net/instal ...

  3. 最大公倍数_Greatest Common Divisor

    计算最大公倍数 Static int gcd( int a, int b) { int t; while( b>0) { t = b; b = a % b; a = t; } return a; ...

  4. 快速排序Quick sort

    快速排序Quick sort 原理,通过一趟扫描将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别进行快速排序,整个排序过程可以递归 ...

  5. 【lydsy1407】拓展欧几里得求解不定方程+同余方程

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1407 题意: 有n个野人,野人各自住在第c[i]个山洞中(山洞成环状),每年向前走p[i] ...

  6. 【BZOJ】1697: [Usaco2007 Feb]Cow Sorting牛排序

    [算法]数学置换 [题意]给定n个数,要求通过若干次交换两个数的操作得到排序后的状态,每次交换代价为两数之和,求最小代价. [题解] 考虑置换的定义:置换就是把n个数做一个全排列. 从原数组到排序数组 ...

  7. 前端&后端程序员必备的Linux基础知识

    一 从认识操作系统开始 1.1 操作系统简介 我通过以下四点介绍什么操作系统: 操作系统(Operation System,简称OS)是管理计算机硬件与软件资源的程序,是计算机系统的内核与基石: 操作 ...

  8. MSSQL 视图/事务(TRAN[SACTION])/存储过程(PROC[EDURE])/触发器(TRIGGER )

    --视图 视图是一张虚拟表,它表示一张表的部分数据或多张表的综合数据,其结构和数据是建立在对表的查询基础上 视图在操作上和数据表没有什么区别,但两者的差异是其本质是不同: 数据表是实际存储记录的地方, ...

  9. js_一个简单的30分钟循环倒计时

    吐槽段: 需求的变更是千变万化的,至少在你说服和你打交道的那位谁谁谁之前. 创业公司就是这样,产品经理一个想法,就是改改改,管你改起来复杂不复杂,在他们眼里都是非常简单的. 今天的一个小改动需求,把活 ...

  10. web-project 故障查看功能 检测是否启动fmd服务

    def check_fmd_service(): try: output = subprocess.check_output('svcs -H -o state fmd',shell=True) st ...