CSU 1412 Line and Circles
原题链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1412
题目要求判断是否有一条直线可以穿过所有的圆。
做法:把所有圆心做一次凸包,然后判断这个凸包是否能通过一个宽度为2*R的通道。

做法和求凸包直径差不多,只是判断的时候把点到两个端点的距离换成点到直线的距离。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
using namespace std; #define inf 1e20
#define eps 1e-8 const int N = ;
const double PI = 2.0*asin(1.0); //高精度求PI
struct Lpoint
{
double x,y;
}a[N], b[N]; //点
struct Llineseg
{
Lpoint a,b;
}; //线段
struct Ldir
{
double dx,dy;
}; //方向向量
struct Lline
{
Lpoint p;
Ldir dir;
}; //直线 bool mult(Lpoint sp, Lpoint ep, Lpoint op)
{
return (sp.x - op.x) * (ep.y - op.y)
>= (ep.x - op.x) * (sp.y - op.y);
} bool operator < (const Lpoint &l, const Lpoint &r)
{
return l.y < r.y || (l.y == r.y && l.x < r.x);
} int graham(Lpoint pnt[], int n, Lpoint res[])
{
int i, len, top = ;
sort(pnt, pnt + n);
if (n == ) return ;
res[] = pnt[];
if (n == ) return ;
res[] = pnt[];
if (n == ) return ;
res[] = pnt[];
for (i = ; i < n; i++)
{
while (top && mult(pnt[i], res[top], res[top-]))
top--;
res[++top] = pnt[i];
}
len = top;
res[++top] = pnt[n - ];
for (i = n - ; i >= ; i--)
{
while (top!=len && mult(pnt[i], res[top], res[top-])) top--;
res[++top] = pnt[i];
}
return top; // 返回凸包中点的个数
} void format(Lline ln, double& A, double& B, double& C)
{
A=ln.dir.dy;
B=-ln.dir.dx;
C=ln.p.y*ln.dir.dx-ln.p.x*ln.dir.dy; } double p2ldis(Lpoint a, Lline ln)
{
double A,B,C;
format(ln,A,B,C);
return(fabs(A*a.x+B*a.y+C)/sqrt(A*A+B*B));
} double CPMD(Lpoint p[], int n)//ConvexPolygonMinimumDiameter
{
int i, j;
double ans = inf, tmp;
p[n] = p[];
Lline ln;
Ldir dir;
for(i = , j = ; i < n; ++i)
{
if((i+)%n == j) j = (j + ) % n;
dir.dx = p[i].x - p[i+].x;
dir.dy = p[i].y - p[i+].y;
ln.dir = dir;
ln.p = p[i];
while((tmp = p2ldis(p[j], ln)) < (p2ldis(p[(j+)%n], ln)))
j = (j + ) % n;
ans = min(ans, tmp);
}
return ans;
} double dis(Lpoint u, Lpoint v)
{
return sqrt((u.x-v.x) * (u.x-v.x) + (u.y - v.y)*(u.y - v.y));
} int main()
{
int n, t;
double r;
scanf("%d", &t);
while(t--)
{
scanf("%d%lf", &n, &r);
for(int i = ; i < n; i++)
scanf("%lf%lf", &a[i].x, &a[i].y);
int m = graham(a, n, b);
if(m <= )
{
printf("Yes\n");
continue;
}
double k = CPMD(b, m);
if(k - *r < eps)
printf("Yes\n");
else
printf("No\n");
}
return ;
}
CSU 1412 Line and Circles的更多相关文章
- matplotlib 柱状图、饼图;直方图、盒图
#-*- coding: utf-8 -*- import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl m ...
- Python图表绘制:matplotlib绘图库入门
matplotlib 是Python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备,并 ...
- 对于fmri的设计矩阵构造的一个很直观的解释-by 西南大学xulei教授
本程序意在解释这样几个问题:完整版代码在本文的最后. 1.实验的设计如何转换成设计矩阵? 2.设计矩阵的每列表示一个刺激条件,如何确定它们? 3.如何根据设计矩阵和每个体素的信号求得该体素对刺激的敏感 ...
- Python图表绘制:matplotlib绘图库入门(转)
matplotlib 是Python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备,并 ...
- Python绘图matplotlib
转自http://blog.csdn.net/ywjun0919/article/details/8692018 Python图表绘制:matplotlib绘图库入门 matplotlib 是pyth ...
- pandas 读写sql数据库
如何从数据库中读取数据到DataFrame中? 使用pandas.io.sql模块中的sql.read_sql_query(sql_str,conn)和sql.read_sql_table(table ...
- matplotlib画图实例:pyplot、pylab模块及作图參数
http://blog.csdn.net/pipisorry/article/details/40005163 Matplotlib.pyplot画图实例 {使用pyplot模块} matplotli ...
- 【Python开发】使用python中的matplotlib进行绘图分析数据
matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备, ...
- csu 1812: 三角形和矩形 凸包
传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...
随机推荐
- [HEOI2014]逻辑翻译
ywy_c_asm的良心题解 是道好题 体现了二进制位的形象递归思想,以及将FWT的思路(都是拆位分治)用到题目中的典范 可以暴力高斯消元.完全没有利用2^N以及+-1的良好性质 发现项数,方程和二进 ...
- switch滑动开关
<!DOCTYPE html> <html> <head > <meta charset="utf-8"> <title> ...
- ELK Betas 6.0安装及使用
Betas 6.0安装及使用 注意: Elastic官网更新非常的快,每个版本的文档有会有不同,具体需要去官网查看最新文档进行配置调整. Beats 平台集合了多种单一用途数据采集器.这些采集器安装后 ...
- 《Apache HttpClient 4.3开发指南》
转载自:http://blog.csdn.net/chszs/article/details/16854747 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chs ...
- Intellj IDEA使用技巧记录
▲.Intellj IDEA光标变成了insert光标状态 且不能编辑操作: https://blog.csdn.net/aosica321/article/details/52787418 ▲.在i ...
- ubuntu学习命令
1.双系统下挂载windows硬盘 检测ntfs-3g是否安装:locate ntfs-3g 没有则安装: sudo apt-get install ntfs-3g 查看硬盘信息: sudo fdis ...
- [USACO14JAN]Recording the Moolympics
题目描述 Being a fan of all cold-weather sports (especially those involving cows), Farmer John wants to ...
- Fire Net(深度优先搜索)
ZOJ Problem Set - 1002 Fire Net Time Limit: 2 Seconds Memory Limit: 65536 KB Suppose that we ha ...
- Eclipse自动代码补全
Windows——>Preferences——>Java-->Editor-->Content Asist, 在Auto activation triggers for Jav ...
- NYOJ 925 国王的烦恼 (并查集)
题目链接 描述 C国由n个小岛组成,为了方便小岛之间联络,C国在小岛间建立了m座大桥,每座大桥连接两座小岛.两个小岛间可能存在多座桥连接.然而,由于海水冲刷,有一些大桥面临着不能使用的危险.如 ...