最小圆覆盖 gym-102006 I
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1.1e-4;
const double PI = acos(-); struct Point {
double x, y;
Point(double x = , double y = ) : x(x), y(y) { }
};
typedef Point Vector; int dcmp(double x) {
if(fabs(x) < eps) return ;
else return x < ? - : ;
} Point operator + (Vector A, Vector B) {return Point(A.x + B.x, A.y + B.y);}
Point operator - (Vector A, Vector B) {return Point(A.x - B.x, A.y - B.y);}
Point operator * (Vector A, double p) {return Point(A.x * p, A.y * p);}
Point operator / (Vector A, double p) {return Point(A.x / p, A.y / p);}
bool operator < (const Vector &A, const Vector &B) {return A.y < B.y || (A.y == B.y && A.x < B.x);}
bool operator == (const Vector &A, const Point &B) {return dcmp(A.x - B.x) == && dcmp(A.y - B.y) == ;}
double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;}
double Length(Vector A) {return sqrt(Dot(A, A));}
double Angle(Vector A, Vector B) {return acos(Dot(A, B) / Length(A) / Length(B));}
double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;}
double Area2(Point A, Point B, Point C) {return Cross(B - A, C - A);} Vector Rotate(Vector A, double rad) {
return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
} double dist(const Point& a, const Point &b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} int n;
double r, R;
Point p[N]; Point GetCircleCenter(Point A, Point B, Point C) {
Point o;
double a1 = B.x-A.x, b1 = B.y-A.y, c1 = (a1*a1+b1*b1)/;
double a2 = C.x-A.x, b2 = C.y-A.y, c2 = (a2*a2+b2*b2)/;
double d = a1*b2-a2*b1;
o.x=A.x+(c1*b2-c2*b1)/d;
o.y=A.y+(a1*c2-a2*c1)/d;
return o;
} void MinPointCoverByCircle(Point *p, int n, Point &o, double &r) {
random_shuffle(p, p+n);
o = p[], r = ;
for(int i = ; i < n; i++) {
if(dist(p[i], o) > r + eps) {
o = p[i]; r = ;
for(int j = ; j < i; j++) {
if(dist(p[j], o) > r + eps) {
o.x = (p[i].x+p[j].x)/;
o.y = (p[i].y+p[j].y)/;
r = dist(p[j], o);
for(int k = ; k < j; k++) {
if(dist(p[k], o) > r + eps) {
o = GetCircleCenter(p[i], p[j], p[k]);
r = dist(p[i], o);
}
}
}
}
}
}
} int main() {
// freopen("robots.in", "r", stdin);
int T; scanf("%d", &T);
while(T--) {
scanf("%d%lf%lf", &n, &R, &r); n++;
p[] = Point(, );
for(int i = ; i < n; i++) {
double x, y; scanf("%lf%lf", &x, &y);
p[i] = p[i-] + Point(x, y);
}
sort(p, p+n);
n = unique(p, p+n)-p;
Point o;
MinPointCoverByCircle(p, n, o, r);
printf("%.12f %.12f\n", -o.x, -o.y);
}
return ;
}
/*
*/
最小圆覆盖 gym-102006 I的更多相关文章
- 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1573 ...
- Bzoj 1336&1337 Alien最小圆覆盖
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special Judge Submit: 1473 ...
- hdu3007Buried memory(最小圆覆盖)
链接 普通的暴力复杂度达到O(n^4),对于这题肯定是不行的. 解法:随机增量算法 参考http://www.2cto.com/kf/201208/149602.html algorithm:A.令C ...
- [BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】
题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...
- [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】
题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...
- 最小圆覆盖 hdu 3007
今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...
- bzoj1336: [Balkan2002]Alien最小圆覆盖
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1336 1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 ...
- 【做题】POI2011R1 - Plot——最小圆覆盖&倍增
原文链接 https://www.cnblogs.com/cly-none/p/loj2159.html 题意:给出\(n\)个点,你需要按编号将其划分成不超过\(m\)段连续的区间,使得所有每个区间 ...
- 【BZOJ2823】[AHOI2012]信号塔(最小圆覆盖)
[BZOJ2823][AHOI2012]信号塔(最小圆覆盖) 题面 BZOJ 洛谷 相同的题: BZOJ1 BZOJ2 洛谷 题解 模板题... #include<iostream> #i ...
- Gym.102006:Syrian Collegiate Programming Contest(寒假自训第11场)
学习了“叙利亚”这个单词:比较温和的一场:几何的板子eps太小了,坑了几发. A .Hello SCPC 2018! 题意:给定一个排列,问它是否满足,前面4个是有序的,而且前面4个比后面的都小. 思 ...
随机推荐
- np.isin判断数组元素在另一数组中是否存在
np.isin用法 觉得有用的话,欢迎一起讨论相互学习~Follow Me np.isin(a,b) 用于判定a中的元素在b中是否出现过,如果出现过返回True,否则返回False,最终结果为一个形状 ...
- Ubuntu如何同步网络时间
解决方法: 1.安装ntpdate工具 apt-get install ntpdate 2.将系统时间与网络同步 ntpdate cn.pool.ntp.org 3.将时间写入硬件 hwclock - ...
- Redis实战(二)CentOS 7上Redis两种方式持久化
Redis的持久化之RDB RDB方式是通过快照完成的,当符合一定条件时Redis会自动将内存中的所有数据进行快照并且存储到硬盘上. 进行快照的条件在配置文件中指定,有2个参数构成:时间和改动的键的个 ...
- [整理]基于bootstrap的文本编辑器
http://www.bootcss.com/p/bootstrap-wysiwyg/ http://jhollingworth.github.io/bootstrap-wysihtml5/ http ...
- 【leetcode 简单】 第八十八题 猜数字大小
我们正在玩一个猜数字游戏. 游戏规则如下: 我从 1 到 n 选择一个数字. 你需要猜我选择了哪个数字. 每次你猜错了,我会告诉你这个数字是大了还是小了. 你调用一个预先定义好的接口 guess(in ...
- cassandra数据库
一.下载地址:http://www.apache.org/dyn/closer.lua/cassandra/3.0.11/apache-cassandra-3.0.11-bin.tar.gz 二.安装 ...
- beego项目运行过程
一:首先man.go,整个程序的入口 func main() { beego.Run() } 然后beego.run()代码 // Run beego application. // beego.Ru ...
- vm tools安装包为空
新装了linux mint虚拟机之后突然发现安装vm tools时为空 1.关闭虚拟机2.打开设置 3.把CD/DVD(SATA)从安装系统时挂载的镜像改为自动检测 4.重启安装vm tools发现没 ...
- linux文件管理 -> 系统目录结构
几乎所有的计算机操作系统都是用目录结构组织文件.具体来说就是在一个目录中存放子目录和文件, 而在子目录中又会进一步存放子目录和文件,以此类推形成一个树状的文件结构,由于其结构很像一棵树的分支, 所以该 ...
- c语言格式控制符
http://zhidao.baidu.com/link?url=-YJjz3U0fd_eSW9eLa8ankGo_QbyOOOaKYWyAY9g4mKWQj0DN6l12OSLJz24U8jCwo1 ...