POJ 3304 Segments 线段交
2013-10-24 22:26
411 查看
计算几何入门
将所有的线段的端点存起来,枚举任意两个端点构成的直线,看是否能穿过所有线段即可
将所有的线段的端点存起来,枚举任意两个端点构成的直线,看是否能穿过所有线段即可
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <cstdlib> #include <cmath> #include <map> #include <sstream> #include <queue> #include <vector> #define MAXN 100005 #define MAXM 211111 #define eps 1e-8 #define INF 500000001 using namespace std; inline int dblcmp(double d) { if(fabs(d) < eps) return 0; return d > eps ? 1 : -1; } 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 a)const { return dblcmp(a.x - x) == 0 && dblcmp(a.y - y) == 0; } point sub(point p) { return point(x - p.x, y - p.y); } double det(point p) { return x * p.y - y * p.x; } }p[3333]; struct line { point a, b; line(){} line(point _a, point _b){ a = _a; b = _b;} void input() { a.input(); b.input(); } int linecrossseg(line v)//v is seg { int d1 = dblcmp(b.sub(a).det(v.a.sub(a))); int d2 = dblcmp(b.sub(a).det(v.b.sub(a))); if ((d1 ^ d2) == -2) return 2; return (d1 == 0 || d2 == 0); } }; int n; int main() { int T; scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 0; i < n; i++) p[2 * i].input(), p[2 * i + 1].input(); int ok = 0; for(int i = 0; i < 2 * n; i++) for(int j = i + 1; j < 2 * n; j++) { if(p[i] == p[j]) continue; int flag = 1; line v = line(p[i], p[j]); for(int k = 0; k < 2 * n; k += 2) { line seg = line(p[k], p[k + 1]); if(v.linecrossseg(seg) == 0) { flag = 0; break; } } if(flag) { ok = 1; break; } } if(ok || n == 1 || n == 2) puts("Yes!"); else puts("No!"); } return 0; }
相关文章推荐
- Windows 8.1中WinRT的变化(二)——新增功能
- Leap::Frame Class Reference 帧类参考
- 黑马程序员--对于面象对象的总结
- SQL优化
- Difference Between Microprocessor and Microcontroller
- 监听总结之有@存在就表示是要通过网络形式来连接而非进程间通讯形式连接
- sqlmap常用命令
- ThinkPad家族全系列解析
- java 调用 C# 类库搞定,三步即可,可以调用任何类及方法,很简单,非常爽啊
- 黑马程序员--方法参数传递的方式
- 写这篇文章并不是教大家怎么样用listview异步加载图片,因为这样的文章在网上已经有很多了,比如这位仁兄写的就很好
- POJ 2318 TOYS 二分+叉积
- java实例三维空间求点之间的距离。。。。
- Flex数据交互之WebService
- C内存相关的题目总结
- ListView异步加载图片是非常实用的方法,凡是是要通过网络获取图片资源一般使用这种方法比较好,用户体验好,下面就说实现方法,先贴上主方法的代码:
- ubuntu 13.04 jdk1.7 ant安装配置
- [wikioi]奇怪的梦境
- tortoiseGIT保存用户名密码
- java 调用 C# 类库搞定,三步即可,可以调用任何类及方法,很简单,非常爽啊