UVA 10005 Packing polygons(最小圆覆盖)

裸的模板题
AC代码:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const double eps = 1e-;
const double pi = acos(-1.0);
const int maxp = ;
int sgn(double x)
{
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
struct Point{
double x, y;
Point(){}
Point(double _x, double _y){
x = _x, y = _y;
}
void input(){
scanf("%lf%lf", &x, &y);
}
bool operator == (Point b) const{
return sgn(x - b.x) == && sgn(y - b.y) == ;
}
bool operator < (Point b)const{
return sgn(x - b.x) == ? sgn(y - b.y < ) : x < b.x;
}
Point operator - (const Point &b)const{
return Point(x - b.x, y - b.y);
}
//²æ»ý
double operator ^(const Point &b){
return x * b.y - y * b.x;
}
//µã»ý
double operator *(const Point &b){
return x * b.x + y * b.y;
}
double len(){
return hypot(x, y);
}
double len2(){
return x * x + y * y;
}
double distant(Point p){
return hypot(x - p.x, y - p.y);
}
Point operator + (const Point &b)const{
return Point (x + b.x, y + b.y);
}
Point operator * (const double &k)const{
return Point(x * k, y * k);
}
Point operator / (const double &k)const{
return Point(x / k, y / k);
}
Point rotate(Point p, double angle){
Point v = (*this) - p;
double c = cos(angle), s = sin(angle);
return Point(p.x + v.x * c - v.y * s, p.y + v.x * s + v.y * c);
}
};
struct polygon{
int n;
Point p[maxp];
void add(Point q){
p[n ++] = q;
}
void input(int _n){
n = _n;
for(int i = ;i < n;i++) p[i].input();
}
Point circumcenter(const Point &a,const Point &b,const Point &c) {
//返回三角形的外心
Point ret;
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;
ret.x = a.x + (c1*b2 - c2*b1) / d;
ret.y = a.y + (a1*c2 - a2*c1) / d;
return ret;
}
void min_cover_circle(Point &c,double &r) { // p为点的集合;c为圆心,r为半径
random_shuffle(p,p+n);
c = p[];
r = ;
for(int i = ; i < n; i++) {
if(c.distant(p[i]) > r + eps) {
c = p[i];
r = ;
for(int j = ; j < i; j++){
if(c.distant(p[j]) > r + eps) {
c.x = (p[i].x + p[j].x) / ;
c.y = (p[i].y + p[j].y) / ;
r = c.distant(p[j]);
for(int k = ; k < j; k++) {
if(c.distant(p[k]) > r + eps) {
c = circumcenter(p[i],p[j],p[k]);
r = c.distant(p[i]);
}
}
}
}
}
}
}
};
int main()
{
int n;
double r;
double ans;
while(~scanf("%d",&n) &&n)
{
polygon a;
Point c;
a.input(n);
scanf("%lf",&r);
a.min_cover_circle(c,ans);
if(ans <= r) printf("The polygon can be packed in the circle.\n");
else printf("There is no way of packing that polygon.\n");
}
return ;
}
UVA 10005 Packing polygons(最小圆覆盖)的更多相关文章
- 【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 ...
随机推荐
- gulp压缩css
gulp压缩css,选用的依赖是gulp-clean-css,在压缩大型项目时还对用到一个dom流压缩文件选取的依赖gulp-dom-src 依赖安装:npm i gulp-clean-css 依赖安 ...
- 线程同步(基于java)
java线程 同步与异步 线程池 1)多线程并发时,多个线程同时请求同一个资源,必然导致此资源的数据不安全,A线程修改了B线 程的处理的数据,而B线程又修改了A线程处理的数理.显然这是由于全局资源造成 ...
- HTML-参考手册: 按字母顺序排列
ylbtech-HTML-参考手册: 按字母顺序排列 1.返回顶部 1. 按字母顺序排列 New : HTML5新标签 标签 描述 <!--...--> 定义注释 <!DOCTYPE ...
- (54) C# 调用 kernel32.dll
https://www.cnblogs.com/cwy173/archive/2010/10/02/1841321.html Kernel32 API AddAtom 向本地原子表添加一个字符串 Al ...
- git操作的日常用法
参考博客: https://blog.csdn.net/afei__/article/details/51567155# 最近一段时间总结一些git在个人日常开发当中用到的方法, 并记录下来, 同时 ...
- Java数据类型简介
Java数据类型 以下两行Java代码定义了两个整数:num1和num2: num1和num2是两个int类型的变量. int关键字指定它的后面是变量的名称,并表示数据类型整数,例如:10,15,70 ...
- XSS漏洞防护
主要是添加黑名单进行拦截 public class XSSFilter implements Filter { private final Log logger = LogFactory.getLog ...
- Jmeter+ InfluxDB+Grafana安装配置
前置条件: 系统:windows jmeter:5.1 InfluxDB安装 下载InfluxDB-v1.7.9和Chronograf-v1.7.14(InfluxDB的可视化web端). 下载完成之 ...
- jmeter Thread Groups的顺序执行与并行执行
本期目标: 理解Thread Groups的顺序执行与并行执行 控制因子:Run Thread Groups consecutively(i.e.one at time) 预期结论: 1.勾选 Run ...
- 转 jmeter 关联
jmeter(十二)关联之正则表达式提取器 如果有这样的情况:一个完整的操作流程,需要先完成某个操作,获得某个值或数据信息,然后才能进行下一步的操作(也就是常说的关联/将上一个请求的响应结果作为下 ...