POJ 3304 Segments | 线段相交
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 105
#define eps 1e-8
using namespace std;
double abs (double x)
{
return x>0?x:-x;
}
bool dcmp(double x,double y)
{
if (abs(x-y)<eps) return 1;
return 0;
}
struct point
{
double x,y;
point () {};
point (double _x,double _y) :
x(_x),y(_y) {};
/*
point operator - (const point &a) const
{
return point (x-a.x,y-a.y);
}
double operator * (const point &rhs) const
{
return x*rhs.y-rhs.x*y;
}
*/
bool operator < (const point &rhs) const
{
return x<rhs.x;
}
friend point operator + (const point &a,const point &b) {
return point(a.x+b.x,a.y+b.y);
}
friend point operator - (const point &a,const point &b) {
return point(a.x-b.x,a.y-b.y);
}
friend double operator * (const point &a,const point &b) {
return a.x*b.y-a.y*b.x;
}
bool operator == (const point &rhs) const
{
return dcmp(x,rhs.x) && dcmp(y,rhs.y);
}
};
struct line
{
point a,b;
}seg[N];
int T,n;
bool check (point l,point z)
{
if (l==z) return 0;
for (int i=1;i<=n;i++)
if(((l-seg[i].a)*(l-z)) *((l-seg[i].b)*(l-z)) > eps) return 0;
return 1;
}
void solve()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%lf%lf%lf%lf",&seg[i].a.x,&seg[i].a.y,&seg[i].b.x,&seg[i].b.y);
if (n<3)
{
puts("Yes!");
return ;
}
for (int i=1;i<=n;i++)
{
for (int j=i+1;j<=n;j++)
if ( check(seg[i].a,seg[j].b) ||
check(seg[i].b,seg[j].a) ||
check(seg[i].a,seg[j].a) ||
check(seg[i].b,seg[j].b))
{
puts("Yes!");
return ;
}
}
puts("No!");
}
int main()
{
scanf("%d",&T);
while (T--)
{
solve();
}
return 0;
}
POJ 3304 Segments | 线段相交的更多相关文章
- poj 3304 Segments 线段与直线相交
Segments Time Limit: 1000MS Memory Limit: 65536K Description Given n segments in the two dim ...
- C - Segments POJ - 3304 (判断线段相交)
题目链接:https://vjudge.net/contest/276358#problem/C 题目大意:给你n条线段,问你是否存在一条线段使得所有的线段在这条直线的投影至少具有一个交点? 具体思路 ...
- POJ 3304 segments 线段和直线相交
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14178 Accepted: 4521 Descrip ...
- POJ 3304 Segments(计算几何:直线与线段相交)
POJ 3304 Segments 大意:给你一些线段,找出一条直线可以穿过全部的线段,相交包含端点. 思路:遍历全部的端点,取两个点形成直线,推断直线是否与全部线段相交,假设存在这种直线,输出Yes ...
- POJ 3304 Segments 判断直线和线段相交
POJ 3304 Segments 题意:给定n(n<=100)条线段,问你是否存在这样的一条直线,使得所有线段投影下去后,至少都有一个交点. 思路:对于投影在所求直线上面的相交阴影,我们可以 ...
- POJ 3304 Segments(判断直线与线段是否相交)
题目传送门:POJ 3304 Segments Description Given n segments in the two dimensional space, write a program, ...
- POJ 3304 Segments 基础线段交判断
LINK 题意:询问是否存在直线,使得所有线段在其上的投影拥有公共点 思路:如果投影拥有公共区域,那么从投影的公共区域作垂线,显然能够与所有线段相交,那么题目转换为询问是否存在直线与所有线段相交.判断 ...
- POJ 3304 Segments (判断直线与线段相交)
题目链接:POJ 3304 Problem Description Given n segments in the two dimensional space, write a program, wh ...
- POJ 3304 Segments (直线和线段相交判断)
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7739 Accepted: 2316 Descript ...
随机推荐
- BZOJ3288: Mato矩阵(欧拉函数 高斯消元)
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 386 Solved: 296[Submit][Status][Discuss] Descriptio ...
- idea中自定义设置xml的头文件的内容
因为在idea中新建的xml默认的头文件,有时候并不是我们需要的这时候可以通过自定义来解决. 如搭建hibernate的实体类的映射xml. 首先 fiel→settings出现 如下框框 在上面搜索 ...
- 区分js中的null,undefined,"",0和false
console.log(typeof null);//object console.log(typeof undefined);//undefined console.log(typeof " ...
- (转)数据库老兵:NewSQL才是未来
编者按:在数据库技术领域,Michael Stonebraker几乎是无人不知无人不晓的人物.现年70岁的Stonebraker不仅是Ingres和PostgreSQL的创始人,同时在Informix ...
- php mysql find_in_set函数 检索单子段 逗号分隔序列
FIND_IN_SET($kwd,field) 例如在 表 AA中 numbers 字段 保存列数据 1,4,8,75,41,7 就可以使用 FIND_IN_SET(8,numbers) 查询记 ...
- 操作 Java 数组的 12 个最佳方法
1. 声明一个数组 Java代码: String[] aArray = new String[5]; String[] bArray = {"a","b",& ...
- python之微信好友统计信息
需要安装库:wxpy 代码如下: from wxpy import Bot,Tuling,embed,ensure_one bot = Bot(cache_path=True) #获取好友信息 bot ...
- R-描述性统计
RT...老实说这一章我是抖的...但是,加油- # 从1:100中均匀抽取size个数据,replace=TRUE指有放回抽样,数据可以重复 x = sample(1:100, size = 100 ...
- 大话卷积神经网络(CNN)
这几年深度学习快速发展,在图像识别.语音识别.物体识别等各种场景上取得了巨大的成功,例如AlphaGo击败世界围棋冠军,iPhone X内置了人脸识别解锁功能等等,很多AI产品在世界上引起了很大的 ...
- 4 CSS的20/80个知识点
1.css的基本构成 样式选择器 id选择器 元素选择器 2.css的盒模型 border padding margin 3.Atom快捷键 4.程序 (1)初始程序 <!DOCTYPE htm ...