嘟嘟嘟




题面就不说了,网上都有。




刚开始理解成了只要有不孤立的线段就算合法,结果就不会了……然而题中要求是所有线段至少有一个交点。

其实想一想就知道,问题转化为了是否存在一条直线和所有线段都有交点。

所以枚举线段的端点构成直线,然后判断直线和线段是否有交点。

具体做法就是对于直线\(AB\),判断线段\(CD\)是否在\(AB\)的两侧,用叉积即可:如果又向面积符号相同,就说明在一侧,即\((\overrightarrow{AB} \times \overrightarrow{AC}) * (\overrightarrow{AB} \times \overrightarrow{AD}) >= 0\)。一定要包含等于\(0\)的情况,这样就不用特判平行和重合的情况。

别忘了还得特判选取的两点是否重合。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 505;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = (ans << 1) + (ans << 3) + ch - '0'; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int n;
struct Vec
{
db x, y;
db operator * (const Vec& oth)const
{
return x * oth.y - oth.x * y;
}
};
struct Point
{
db x, y;
Vec operator - (const Point& oth)const
{
return (Vec){x - oth.x, y - oth.y};
}
}a[maxn], b[maxn]; bool judge(Point A, Point B)
{
Vec AB = B - A;
if(fabs(A.x - B.x) < eps && fabs(A.y - B.y) < eps) return 0;
for(int i = 1; i <= n; ++i)
{
Vec AC = a[i] - A, AD = b[i] - A;
if((AB * AC) * (AB * AD) > eps) return 0;
}
return 1;
} int main()
{
int T = read();
while(T--)
{
n = read();
for(int i = 1; i <= n; ++i)
scanf("%lf%lf%lf%lf", &a[i].x, &a[i].y, &b[i].x, &b[i].y);
bool flg = 0;
if(n < 3) flg = 1;
for(int i = 1; i < n && !flg; ++i)
{
flg = 0;
for(int j = i + 1; j <= n && !flg; ++j)
{
if(judge(a[i], a[j])) flg = 1;
else if(judge(a[i], b[j])) flg = 1;
else if(judge(b[i], a[j])) flg = 1;
else if(judge(b[i], b[j])) flg = 1;
}
}
puts(flg ? "Yes!" : "No!");
}
return 0;
}

POJ3304 Segments的更多相关文章

  1. poj3304 Segments【计算几何】

    C - Segments POJ - 3304 最近开始刷计算几何了 公式好多完全不会 数学不行 几何不行 记忆力不行 当机 查的题解 就当复习吧 这套专题拿来熟悉一下计算几何模板 #include ...

  2. POJ3304:Segments (几何:求一条直线与已知线段都有交点)

    Given n segments in the two dimensional space, write a program, which determines if there exists a l ...

  3. POJ3304 Segments 【线段直线相交】

    题意: 给出n条线段两个端点的坐标,问所有线段投影到一条直线上,如果这些所有投影至少相交于一点就输出Yes!,否则输出No!. 思路: 计算几何.这道题要思考到两点: 1:把问题转化为是否存在一条直线 ...

  4. 【kuangbin专题】计算几何基础

    1.poj2318 TOYS 传送:http://poj.org/problem?id=2318 题意:有m个点落在n+1个区域内.问落在每个区域的个数. 分析:二分查找落在哪个区域内.叉积判断点与线 ...

  5. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

  6. POJ3304:Segments——题解

    http://poj.org/problem?id=3304 题目大意:给n条线段,求是否存在一条直线,将所有线段投影到上面,使得所有投影至少交于一点. ——————————————————————— ...

  7. [LeetCode] Number of Segments in a String 字符串中的分段数量

    Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...

  8. Greenplum记录(一):主体结构、master、segments节点、interconnect、performance monitor

    结构:Client--master host--interconnect--segment host 每个节点都是单独的PG数据库,要获得最佳的性能需要对每个节点进行独立优化. master上不包含任 ...

  9. Application package 'AndroidManifest.xml' must have a minimum of 2 segments.

    看了源码就是packagename里面必须包含一个. 源码在: ./sdk/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/id ...

随机推荐

  1. HDU 2041--超级楼梯(递推求解)

    Description 有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?   Input 输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每 ...

  2. 单点登录-SSO

    单点登录 (Single Sign-On ) 1.同域单点登录 登录的时候,设置cookie的域即可. 2.跨域单点登录 重点是,如何在浏览器端保存登录的标识. 祭图:(脑补) 三个系统: a.aaa ...

  3. k:特殊的线性表—栈

    栈(Stack):  栈是一种特殊的线性表,栈中的数据元素以及数据元素之间的逻辑关系和线性表相同,两者之间的差别在于:线性表的插入和删除操作可以在表的任意位置进行,而栈的插入和删除操作只允许在表的尾端 ...

  4. Java NIO文章列表(强烈推荐 转)

    IO流学习总结 一 Java IO,硬骨头也能变软 二 java IO体系的学习总结 三 Java IO面试题 NIO与AIO学习总结 一 Java NIO 概览 二 Java NIO 之 Buffe ...

  5. 判断是手机端还是电脑端 isMobile()

    1.在PublicController控制器中写好判断手机端方法. <?php namespace Home\Controller; use Think\Controller; class Pu ...

  6. [转]Tips——Chrome DevTools - 25 Tips and Tricks

    Chrome DevTools - 25 Tips and Tricks 原文地址:https://www.keycdn.com/blog/chrome-devtools 如何打开? 1.从浏览器菜单 ...

  7. js生成qq客服在线代码

    说到QQ客服在线代码,随便那么百度谷歌一下就会出来,一般都是 <a target="blank" href="http://wpa.qq.com/msgrd?V=1 ...

  8. axios中设置post请求,后台却无法识别参数

    场景:在使用iview时,定义api请求时,代码如下 export const delWord = (data) => { return axios.request({ url: '/words ...

  9. Css选择器(上) 让样式无孔不入

    css选择器    一个可以选择样式的工具, 这里适用于无论是内部代码还是外部引用 abc.css 这类型的文件. 基本选择器*{ }        就是一个简单的*, 代表应用于全部. 不适合于个性 ...

  10. Web开发须知的浏览器内幕 缓存与存储篇(1)

    本文禁止转载,由UC浏览器内部出品. 0.前言 大纲 浏览器缓存和存储相关的功能分为四类: 加载流程 Memory Cache Application Cache(简称AppCache) HTTP C ...