判断线段和直线相交 POJ 3304
// 判断线段和直线相交 POJ 3304
// 思路:
// 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交。 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long LL;
const LL inf = 1e18;
const int N = ;
const double eps = 1e-; int sgn(double x){
if(fabs(x)<eps) return ;
if(x<) return -;
return ;
} struct Point{
double x,y;
Point(){}
Point(double _x,double _y){
x=_x;y=_y;
}
Point operator -(const Point &b)const{
return Point(x-b.x,y-b.y);
}
double operator *(const Point &b)const{
return x*b.x+y*b.y;
}
double operator ^(const Point &b)const{
return x*b.y-y*b.x;
}
}; struct Line{
Point s,e;
Line(){}
Line(Point _s,Point _e){
s=_s,e=_e;
}
}; double xmult(Point p0,Point p1,Point p2){
return (p1-p0)^(p2-p0);
} bool Seg_inter_line(Line l1,Line l2){
return sgn(xmult(l2.s,l1.s,l1.e))*sgn(xmult(l2.e,l1.s,l1.e))<=;
} double dist(Point a,Point b){
return sqrt((a-b)*(a-b));
}
Line line[N];
bool work(Line l1,int n){
if(sgn(dist(l1.s,l1.e))==) return false;
for(int i=;i<n;i++){
if(Seg_inter_line(l1,line[i])==false) return false;
}
return true;
}
int main(){
int n,T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
double x1,y1,x2,y2;
for(int i=;i<n;i++){
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
line[i]=Line(Point(x1,y1),Point(x2,y2));
}
bool flag=false;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
if(work(Line(line[i].s,line[j].e),n)||work(Line(line[i].s,line[j].s),n)||work(Line(line[i].e,line[j].e),n)||work(Line(line[i].e,line[j].s),n)){
flag=true;
break;
}
}
if(flag) break;
}
if(flag) puts("Yes!");
else puts("No!");
}
return ;
}
判断线段和直线相交 POJ 3304的更多相关文章
- POJ 1039 Pipe【经典线段与直线相交】
链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 3304 /// 判断线段与直线是否相交
题目大意: 询问给定n条线段 是否存在一条直线使得所有线段在直线上的投影存在公共点 这个问题可以转化为 是否存在一条直线与所有的线段同时相交 而枚举直线的问题 因为若存在符合要求的直线 那么必存在穿过 ...
- 线段和矩形相交 POJ 1410
// 线段和矩形相交 POJ 1410 // #include <bits/stdc++.h> #include <iostream> #include <cstdio& ...
- 直线相交 POJ 1269
// 直线相交 POJ 1269 // #include <bits/stdc++.h> #include <iostream> #include <cstdio> ...
- 判断直线与线段相交 POJ 3304 Segments
题意:在二维平面中,给定一些线段,然后判断在某直线上的投影是否有公共点. 转化,既然是投影,那么就是求是否存在一条直线L和所有的线段都相交. 证明: 下面给出具体的分析:先考虑一个特殊的情况,即n=1 ...
- poj 3304线段与直线相交
http://poj.org/problem?id=3304 Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- poj 3304 Segments 线段与直线相交
Segments Time Limit: 1000MS Memory Limit: 65536K Description Given n segments in the two dim ...
- POJ 1410--Intersection(判断线段和矩形相交)
Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16322 Accepted: 4213 Des ...
- poj 1410 Intersection (判断线段与矩形相交 判线段相交)
题目链接 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12040 Accepted: 312 ...
随机推荐
- Linux 查找软件安装路径
root@kali:~# whereis sqlmap sqlmap: /usr/bin/sqlmap /usr/share/sqlmap /usr/share/man/man1/sqlmap..gz ...
- JCIFS读取远程服务器文件过慢的解决方法
JCIFS读取远程服务器文件过慢的解决方法 发表于3年前(2013-07-12 11:23) 阅读(1174) | 评论(0) // 我要收藏"; var favor_del = &qu ...
- Android WIFI 操作
代码 package com.wifitest; import java.util.List; import android.content.Context; import android.net.w ...
- 关于矩阵最通俗的解释-超级经典zz
线性代数课程,无论你从行列式入手还是直接从矩阵入手,从一开始就充斥着莫名其妙.比如说,在全国一般工科院系教学中应用最广泛的同济线性代数教材(现在到了第四版),一上来就介绍逆序数这个“前无古人,后无来者 ...
- YCM安装与配置
1.重新编译vim 2.通过vundle安装YCM 3.安装CMake 4.下载预先编译好的llvm+clang 5.看官网的命令,生成CMake的编译文件并编译 配置YCM: 要额外配置ycm_ex ...
- 一个简单json数据提交实例
1.客户端编程:jsp页面 <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- ffmpeg 2.8.1 最新版本 VS2013 可调式动态库
ffmpeg 2.8.1 最新版本 VS2013 可调式动态库 由于大多数初学者都在想尽各种版本寻求VC编译调试ffmpeg的版本,我也曾经移植过几个版本的ffmpeg到VC上编译.: 链接所需动态库 ...
- vim常用命令 vim键盘布局
vim键盘布局,vim快捷键 vim常用命令:
- fzu Problem 2140 Forever 0.5(推理构造)
题目:http://acm.fzu.edu.cn/problem.php?pid=2140 题意: 题目大意:给出n,要求找出n个点,满足: 1)任意两点间的距离不超过1: 2)每个点与(0,0)点的 ...
- MyBatis 实践 -Mapper与DAO
MyBatis 实践 标签: Java与存储 MyBatis简介 MyBatis前身是iBatis,是一个基于Java的数据持久层/对象关系映射(ORM)框架. MyBatis是对JDBC的封装,使开 ...