// 判断线段和直线相交 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的更多相关文章

  1. POJ 1039 Pipe【经典线段与直线相交】

    链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  2. POJ 3304 /// 判断线段与直线是否相交

    题目大意: 询问给定n条线段 是否存在一条直线使得所有线段在直线上的投影存在公共点 这个问题可以转化为 是否存在一条直线与所有的线段同时相交 而枚举直线的问题 因为若存在符合要求的直线 那么必存在穿过 ...

  3. 线段和矩形相交 POJ 1410

    // 线段和矩形相交 POJ 1410 // #include <bits/stdc++.h> #include <iostream> #include <cstdio& ...

  4. 直线相交 POJ 1269

    // 直线相交 POJ 1269 // #include <bits/stdc++.h> #include <iostream> #include <cstdio> ...

  5. 判断直线与线段相交 POJ 3304 Segments

    题意:在二维平面中,给定一些线段,然后判断在某直线上的投影是否有公共点. 转化,既然是投影,那么就是求是否存在一条直线L和所有的线段都相交. 证明: 下面给出具体的分析:先考虑一个特殊的情况,即n=1 ...

  6. poj 3304线段与直线相交

    http://poj.org/problem?id=3304 Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: ...

  7. poj 3304 Segments 线段与直线相交

    Segments Time Limit: 1000MS   Memory Limit: 65536K       Description Given n segments in the two dim ...

  8. POJ 1410--Intersection(判断线段和矩形相交)

    Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16322   Accepted: 4213 Des ...

  9. poj 1410 Intersection (判断线段与矩形相交 判线段相交)

    题目链接 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12040   Accepted: 312 ...

随机推荐

  1. Spring整合CXF,发布RSETful 风格WebService(转)

    Spring整合CXF,发布RSETful 风格WebService 这篇文章是承接之前CXF整合Spring的这个项目示例的延伸,所以有很大一部分都是一样的.关于发布CXF WebServer和Sp ...

  2. Tomcat启动后访问首页报错 显示JSP 空指针异常

    HTTP Status 500 - type Exception report message description The server encountered an internal error ...

  3. ossec 常用命令及目录说明

    1. /var/www/html/analogi -> ossec 第三方的web界面的安装目录 [root@ossec-server ~]# cd /var/www/html/analogi/ ...

  4. MFC多文档中opencv处理图像打开、保存

    需要在C**Doc和C**View中进行相应修改 图像打开: Doc.cpp中: BOOL CCVMFCDoc::Load(IplImage** pp, LPCTSTR csFilename) { I ...

  5. Linux kmalloc/kfree 源码解读

    kmalloc/kfree用于划分和回收内核空间低区内存的方法.改组方法没有直接通过伙伴系统进行内存的划分,通过slab算法进行分配的.同时也为每个CPU提供一个阵列缓存,用于提高分配效率.下面对改组 ...

  6. IOS代码

    //// MJViewController.m// UITableView-编辑模式//// Created by mj on 13-4-11.// Copyright (c) 2013年 itcas ...

  7. Jenkins iOS – Git, xcodebuild, TestFlight

    Introduction with Jenkins iOS If you are new to continuous integration for mobile platforms then you ...

  8. poj 1067 取石子游戏( 威佐夫博奕)

    题目:http://poj.org/problem?id=1067 题意:有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的 ...

  9. uva live 6170

    Esspe-Peasee Esspe-Peasee is an ancient game played by children throughout the land of Acmania. The ...

  10. UVa 1252 (状压DP + 记忆化搜索) Twenty Questions

    题意: 有n个长为m的各不相同的二进制数(允许存在前导0),别人已经事先想好n个数中的一个数W,你要猜出这个数. 每次只可以询问该数的第K为是否为1. 问采用最优询问策略,则最少需要询问多少次能保证猜 ...