POJ 3304 Segment
来源:互联网 发布:真维斯淘宝店电话 编辑:程序博客网 时间:2024/05/16 07:09
直线与线段相交,枚举直线的端点 用叉积判断是否有交点
#include "cstring"#include "iostream"#include "algorithm"#include "cstdio"#include "queue"#include "set"#include "cmath"using namespace std;typedef long long LL;const int M=510;const int INF = 0x3f3f3f3f;const double PI = acos(-1.00);const double eps = 10e-8;struct point{ double x,y;};int n;struct node{// struct point// {// double x,y;// }; point s,t;} s[105];int dis(point a,point b){ double d; d=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); if(-eps<=d && d<=eps) return 0; return 1;}double chaji(point a,point b,point c) //x1*y2-x2*y1{ return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);}double judge(point a,point b){ if(!dis(a,b)) return 0; for(int i=1; i<=n; i++) //判断是否有交点 if(chaji(a, b, s[i].s)*chaji(a, b, s[i].t) > eps) return 0; return 1;}int main(){ int t; cin>>t; while(t--) { cin>>n; for(int i=1; i<=n; ++i) { cin>>s[i].s.x>>s[i].s.y>>s[i].t.x>>s[i].t.y; } int flag=0; if(n==1) flag=1; for(int i=1; i<n; i++) //枚举线段的端点 for(int j=i+1; j<=n; j++) if(judge(s[i].s, s[j].s)||judge(s[i].s, s[j].t)||judge(s[i].t, s[j].s)||judge(s[i].t, s[j].t)) { flag=1; break; } cout<<(flag?"Yes!":"No!")<<endl; } return 0;}
0 0
- POJ 3304 Segment
- POJ 3304 Segment 直线与线段相交
- POJ 3304 Segment 直线与线段相交
- POJ 3304 Segment 直线与线段相交 + 枚举
- POJ 3368 Frequent values [Segment Tree]
- POJ 2828 Buy Tickets - Segment Tree
- segment
- Segment
- Segment
- Segment
- Segment
- segment
- poj 3264 线段树 寻找最大最小值 SEGMENT TREE
- poj 1558-Segment set (并查集+计算几何)
- POJ 2828 Buy Tickets ( Splay tree && Segment tree )
- poj 3468 A Simple Problem with Integers (线段树 segment tree)
- POJ 3468 A Simple Problem with Integers Splay tree&Segment tree
- POJ 3264——Balanced Lineup(RMQ ,segment tree,树状数组)
- [DFS] AOJ 0118 Property Distribution
- HDU 1735 字数统计
- HDUOJ1091
- 奇偶剪枝
- 实习第四天——安卓开发中遇到的问题
- POJ 3304 Segment
- OpenCV入门笔记(一) Linux下的安装
- 一致性哈希算法
- java定时器
- 笔记:sh中从提交一个表单开始发生了什么
- pandas常用操作
- 【计蒜客系列】挑战难题18:跳跃游戏
- js动画2 多物体运动
- HDOJ 2035 人见人爱A^B(快速幂取模)