POJ3304 Segments
嘟嘟嘟
题面就不说了,网上都有。
刚开始理解成了只要有不孤立的线段就算合法,结果就不会了……然而题中要求是所有线段至少有一个交点。
其实想一想就知道,问题转化为了是否存在一条直线和所有线段都有交点。
所以枚举线段的端点构成直线,然后判断直线和线段是否有交点。
具体做法就是对于直线\(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的更多相关文章
- poj3304 Segments【计算几何】
C - Segments POJ - 3304 最近开始刷计算几何了 公式好多完全不会 数学不行 几何不行 记忆力不行 当机 查的题解 就当复习吧 这套专题拿来熟悉一下计算几何模板 #include ...
- POJ3304:Segments (几何:求一条直线与已知线段都有交点)
Given n segments in the two dimensional space, write a program, which determines if there exists a l ...
- POJ3304 Segments 【线段直线相交】
题意: 给出n条线段两个端点的坐标,问所有线段投影到一条直线上,如果这些所有投影至少相交于一点就输出Yes!,否则输出No!. 思路: 计算几何.这道题要思考到两点: 1:把问题转化为是否存在一条直线 ...
- 【kuangbin专题】计算几何基础
1.poj2318 TOYS 传送:http://poj.org/problem?id=2318 题意:有m个点落在n+1个区域内.问落在每个区域的个数. 分析:二分查找落在哪个区域内.叉积判断点与线 ...
- poj分类解题报告索引
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...
- POJ3304:Segments——题解
http://poj.org/problem?id=3304 题目大意:给n条线段,求是否存在一条直线,将所有线段投影到上面,使得所有投影至少交于一点. ——————————————————————— ...
- [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 ...
- Greenplum记录(一):主体结构、master、segments节点、interconnect、performance monitor
结构:Client--master host--interconnect--segment host 每个节点都是单独的PG数据库,要获得最佳的性能需要对每个节点进行独立优化. master上不包含任 ...
- Application package 'AndroidManifest.xml' must have a minimum of 2 segments.
看了源码就是packagename里面必须包含一个. 源码在: ./sdk/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/id ...
随机推荐
- IntelliJ使用指南—— 导入Eclipse的Web项目
通常一个团队中可能有人用eclipse,有人用intelliJ,那么经常会出现需要导入别人用eclipse建好的web项目.而IntelliJ提供了多种项目类型的导入方式,其中就有eclipse. 在 ...
- HDU 1875(最小生成树)
因为是全连接图,所以也可以用最小生成树 这道题给边加了一个限制条件,(10<=x<=1000),所以可能不能全连通,需要判断 #include <cstdio> #includ ...
- spring boot包扫描不到controller层
启动类代码 package com.maven.demo; import org.mybatis.spring.annotation.MapperScan; import org.springfram ...
- 记录一次teamview无法远程连接对方teamview的过程
问题描述: teamviewer 提示 超时后连接被阻断.您的许可证对您与伙伴的最大话时间有所限制...... 解决方法: 1.先将自己的teamview完全卸载,连同安装目录一起删除.尽量卸载完全 ...
- 基于jQuery日历插件制作日历
这篇文章主要介绍了基于jQuery日历插件制作日历的相关资料,需要的朋友可以参考下 来看下最终效果图吧: 是长得丑了一点,不要吐槽我-.- 首先来说说这个日历主要的制作逻辑吧: ·一个月份最多有31天 ...
- iview-admin2中vue.config配置文件輸出路徑
在vue.config.js文件中添加如下信息 module.exports = { baseUrl: '', // 可以配置生产和测试环境下,文件的路径(即index中引用的路径,但不会在dist中 ...
- AJAX 概念 优势 发展前景 工作原理 底层技术 状态 缺点 框架
1. 概念 Ajax asynchronous JavaScript and XML , 异步js和xml. 这种解释已经过时了, 现在ajax就是, 允许浏览器和服务器通信, 而无需刷新当前页面的技 ...
- 对一些ArcGIS for JS的API的一些理解
1.esri/map map类是每个地图控件中必须引入的类,我们可以通过Map()对地图进行许多的操作,比如修改地图的坐标系.显示级别和初始显示范围等等. Map有一个类型为GraphicsLay ...
- Appium元素定位(uiautomatorviewer)
一.uiautomatorviewer元素定位 1.adroid-sdk的安装目录tools下有1个自带的工具uiautomatorviewer,打开后,如下所示: 点击后,如图所示: 步骤: a.链 ...
- Selenium之TestNG安装
一.在Eclipse中安装TestNG 1.打开eclipse-->help-->Install New Software-->Add,输入Name和Location后,点击OK. ...