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 = 100005 ;
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 = 1;
sort(pnt, pnt + n);
if (n == 0) return 0;
res[0] = pnt[0];
if (n == 1) return 1;
res[1] = pnt[1];
if (n == 2) return 2;
res[2] = pnt[2];
for (i = 2; i < n; i++)
{
while (top && mult(pnt[i], res[top], res[top-1]))
top--;
res[++top] = pnt[i];
}
len = top;
res[++top] = pnt[n - 2];
for (i = n - 3; i >= 0; i--)
{
while (top!=len && mult(pnt[i], res[top], res[top-1])) 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[0];
Lline ln;
Ldir dir;
for(i = 0, j = 1; i < n; ++i)
{
if((i+1)%n == j) j = (j + 1) % n;
dir.dx = p[i].x - p[i+1].x;
dir.dy = p[i].y - p[i+1].y;
ln.dir = dir;
ln.p = p[i];
while((tmp = p2ldis(p[j], ln)) < (p2ldis(p[(j+1)%n], ln)))
j = (j + 1) % 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 = 0; i < n; i++)
scanf("%lf%lf", &a[i].x, &a[i].y);
int m = graham(a, n, b);
if(m <= 2)
{
printf("Yes\n");
continue;
}
double k = CPMD(b, m);
if(k - 2*r < eps)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}

CSU 1412 Line and Circles,布布扣,bubuko.com

时间: 2024-07-30 10:18:53

CSU 1412 Line and Circles的相关文章

Python进阶(三十九)-数据可视化の使用matplotlib进行绘图分析数据

Python进阶(三十九)-数据可视化の使用matplotlib进行绘图分析数据 ??matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. ??它的文档相当完备,并且 Gallery页面 中有上百幅缩略图,打开之后都有源程序.因此如果你需要绘制某种类型的图,只需要在这个页面中浏览/复制/粘贴一下,基本上都能搞定. ??在Linux下比较著名的数据图工具还有gnuplot

python matplotlib 基础

简介 matplotlib是python里面的一个专业绘图工具库,如果想通过python来绘制漂亮的图形,那么一定少不了它了. 准备 在开始画图之前需要安装numpy以及matplotlib库,当然python基本库也必不可少,numpy是一个专业的数组,矩阵处理工具. ? Python ? Numpy - this is the module which does most array and mathematical manip- ulation ? Matplotlib - this is

使用python中的matplotlib进行绘图分析数据

http://blog.csdn.net/pipisorry/article/details/37742423 matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备,并且 Gallery页面 中有上百幅缩略图,打开之后都有源程序.因此如果你需要绘制某种类型的图,只需要在这个页面中浏览/复制/粘贴一下,基本上都能搞定. 在Linux下比较著名的数据图工具

Python图表绘制:matplotlib绘图库入门

matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备,并且Gallery页面中有上百幅缩略图,打开之后都有源程序.因此如果你需要绘制某种类型的图,只需要在这个页面中浏览/复制/粘贴一下,基本上都能搞定. 在Linux下比较著名的数据图工具还有gnuplot,这个是免费的,Python有一个包可以调用gnuplot,但是语法比较不习惯,而且画图质量不高.

Python绘图matplotlib

转自http://blog.csdn.net/ywjun0919/article/details/8692018 Python图表绘制:matplotlib绘图库入门 matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备,并且Gallery页面中有上百幅缩略图,打开之后都有源程序.因此如果你需要绘制某种类型的图,只需要在这个页面中浏览/复制/粘贴一下,基

CSU 1547 Rectangle(dp、01背包)

题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1547 Description Now ,there are some rectangles. The area of these rectangles is 1* x or 2 * x ,and now you need find a big enough rectangle( 2 * m) so that you can put all rectangles into it(th

计数方法,博弈论(扫描线,树形SG):HDU 5299 Circles Game

There are n circles on a infinitely large table.With every two circle, either one contains another or isolates from the other.They are never crossed nor tangent.Alice and Bob are playing a game concerning these circles.They take turn to play,Alice go

CSU 1601 War (并查集)

1601: War Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 202  Solved: 58 [Submit][Status][Web Board] Description AME decided to destroy CH's country. In CH' country, There are N villages, which are numbered from 1 to N. We say two village A and B ar

Calling Circles

Description: If you've seen television commercials for long-distance phone companies lately, you've noticed that many companies have been spending a lot of money trying to convince people that they provide the best service at the lowest cost. One com