poj 3304 Segments(线段与直线相交)
来源:互联网 发布:win10激活工具 知乎 编辑:程序博客网 时间:2024/05/21 17:52
http://poj.org/problem?id=3304
Description
Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on it, all projected segments have at least one point in common.
Input
Input begins with a number T showing the number of test cases and then, T test cases follow. Each test case begins with a line containing a positive integer n ≤ 100 showing the number of segments. After that, n lines containing four real numbers x1 y1 x2 y2 follow, in which (x1, y1) and (x2, y2) are the coordinates of the two endpoints for one of the segments.
Output
For each test case, your program must output "Yes!", if a line with desired property exists and must output "No!" otherwise. You must assume that two floating point numbers a and b are equal if |a - b| < 10-8.
Sample Input
321.0 2.0 3.0 4.04.0 5.0 6.0 7.030.0 0.0 0.0 1.00.0 1.0 0.0 2.01.0 1.0 2.0 1.030.0 0.0 0.0 1.00.0 2.0 0.0 3.01.0 1.0 2.0 1.0
Sample Output
Yes!Yes!No!
题意:给定n条线段,确定是否存在一条直线,使得这n条线段在这条直线上的射影具有公共点
可将问题转化为是否存在一条直线经过所有的线段
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<cmath>using namespace std;#define N 5110#define INF 0x3f3f3f3f#define MOD#define EPS 1e-8#define met(a, b) memset(a, b, sizeof(a))typedef long long LL;using namespace std;struct point{ double x, y;};struct Line{ point a, b;};Line p[N];int n;double xmult (point p1, point p2, point p0)///叉积{ return (p1.x-p0.x) * (p2.y-p0.y) - (p2.x-p0.x) * (p1.y-p0.y);}double Dis (point a, point b)///判断两线段端点是否重点{ return sqrt ((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));}bool Judge (point a, point b)///判断两点的连线和其他所有线段是否有交点{ if (Dis (a, b) < EPS) return false;///判断两线段端点是否重点 for (int i=1; i<=n; i++) if (xmult (p[i].a, a, b) * (xmult (p[i].b, a, b)) > EPS) return false; return true;}int main (){ int T; scanf ("%d", &T); while (T--) { met (p, 0); scanf ("%d", &n); bool flag = false; for (int i=1; i<=n; i++) scanf ("%lf%lf%lf%lf", &p[i].a.x, &p[i].a.y, &p[i].b.x, &p[i].b.y); for (int i=1; i<=n; i++) { if (Judge (p[i].a, p[i].b)) flag = true; for (int j=i+1; j<=n && !flag; j++) { if (Judge (p[i].a, p[j].a) || Judge (p[i].a, p[j].b) || Judge (p[i].b, p[j].a) || Judge (p[i].b, p[j].b)) { flag = true; break; } } if (flag) break; } if (flag) puts ("Yes!"); else puts ("No!"); } return 0;}
- poj-3304-Segments-线段与直线相交
- poj 3304 Segments 线段与直线相交
- POJ 3304 Segments (直线与线段相交)
- POJ 3304 Segments(计算几何:直线与线段相交)
- POJ 3304 segments (直线与线段相交)
- poj 3304 Segments(线段与直线相交)
- poj 3304 Segments(贪心+直线是否与线段相交!)
- poj 3304Segments(直线与线段的相交关系)
- poj 3304 Segments(线段与直线相交)
- poj 3304 Segments(判断直线与线段相交)
- POJ 3304 Segments(判线段与直线相交)
- POJ 3304 Segments(直线与线段相交判定)
- POJ 3304 Segments 判断直线与线段相交
- poj 3304 Segments--直线和线段相交
- POJ 3304 Segments(线段直线相交)
- POJ 3304 || Segments (线段,直线相交
- Poj 3304 Segments 【线段于直线相交】
- 【线段直线相交】POJ 3304 Segments
- java 序列化
- 2016-NJUST-琪露诺的算术教室
- C#连接数据库的三种方法
- 初次涉及Java领域的感受
- 关于 TortoiseSVN:由于目标机器积极拒绝,无法连接,的一种解决办法
- poj 3304 Segments(线段与直线相交)
- JVM
- iOS单元测试(作用及入门提升)
- 使用icomet 实现长轮询
- 设置本地时间_简单版
- 解决cmd下快捷键切换不了中文的原因
- Java的很多方面都比较了解了
- Canvas实战---时钟
- Android 混淆打包时第三方jar包报错Unknown verification type [*] in stack map frame