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 ...
随机推荐
- php打包下载文件
使用前请先开启:查看下php.ini里面的extension=php_zip.dll前面的分号有没有去掉; $zip=new \ZipArchive(); $zifile = 'download/' ...
- HTML5: HTML5 Web 存储
ylbtech-HTML5: HTML5 Web 存储 1.返回顶部 1. HTML5 Web 存储 HTML5 web 存储,一个比cookie更好的本地存储方式. 什么是 HTML5 Web 存储 ...
- CentOS安装 netdata 实时监视 Linux 系统性能
作为一个 Linux 系统的管理员,为了随时了解系统资源的占用情况,有必要使用专门的系统监视工具.如果你需要对 Linux 系统.应用程序.SNMP 设备进行实时的性能监视,那么 netdata 这个 ...
- npm ERR! cb() never called! npm ERR! This is an error with npm itself. Pleas
原因是:需要用管理员的身份才能进行 方法:点开始,找到命令提示符,右键,点以管理员的身份运行命令即可
- mysql三种连接方式
sql四种连接方式demo: 表a 表b a.id与b.parent_id有关系 1.内连接:SELECT a.*,b.* from a INNER JOIN b ON a.id=b.parent_i ...
- vue 使用pug(详细说明)
1.安装pug npm i -D pug pug-html-loader pug-plain-loader cli2.0脚手架修改build/webpack.base.conf.js文件 module ...
- stat - 打印信息节点(inode)内容
SYNOPSIS(总览) stat filename [filenames ... ] DESCRIPTION(描述) stat 打印出一个信息节点的内容,它们显示为对人可读的格式的stat(2). ...
- JS window对象 Navigator对象 Navigator 对象包含有关浏览器的信息,通常用于检测浏览器与操作系统的版本。
Navigator对象 Navigator 对象包含有关浏览器的信息,通常用于检测浏览器与操作系统的版本. 对象属性: 查看浏览器的名称和版本,代码如下: <script type=" ...
- 八、结构模式之组合(Composite)模式
组合模式属于对象的结构模式,有时又叫做部分-整体模式,组合模式将对象组织到树结构中,可以用来描述整体与部分的联系.其可以使客户端将单纯元素和组合元素同等对待. 当需求中是体现部分与整体层次的结构时,以 ...
- Circular Coloring
Circular Coloring 将n个0,m个1进行圆周排列,定义一个排列的权值为圆上所有相邻且相同的数字组成一段的段长的乘积,询问断环成链所有方案的权值之和,\(n,m\leq 5000\). ...