题目链接:http://poj.org/problem?id=3304

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = ;
const int maxe = ;
const int INF = 0x3f3f3f;
const double eps = 1e-;
const double PI = acos(-1.0); struct Point{
double x,y;
Point(double x=, double y=) : x(x),y(y){ } //构造函数
};
typedef Point Vector; Vector operator + (Vector A , Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Vector A , Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A , double p){return Vector(A.x*p,A.y*p);}
Vector operator / (Vector A , double p){return Vector(A.x/p,A.y/p);} bool operator < (const Point& a,const Point& b){
return a.x < b.x ||( a.x == b.x && a.y < b.y);
}
int dcmp(double x){
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
bool operator == (const Point& a, const Point& b){
return dcmp(a.x - b.x) == && dcmp(a.y - b.y) == ;
} double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; }
double Cross(Vector A, Vector B) { return A.x*B.y - A.y * B.x; }
double Length(Vector A) { return sqrt(Dot(A,A)); } bool SegmentLineIntersection(Point a1,Point a2,Point b1,Point b2){ //a1a2是直线,b1b2是线段;
double c1 = Cross(a2-a1,b1-a1), c2 = Cross(a2-a1,b2-a1); return dcmp(c1) * dcmp(c2) < || dcmp(c1) == || dcmp(c2) == ;
} Point read_point(){
Point A;
scanf("%lf %lf",&A.x,&A.y);
return A;
} /******************************分割线*******************************/ Point P[maxn][];
int n; int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
int T;
cin>>T;
while(T--){
cin>>n;
for(int i=;i<=n;i++){
P[i][] = read_point();
P[i][] = read_point();
}
bool ans = false;
for(int i=;i<n;i++)
for(int k=;k<=;k++)
for(int j=i+;j<=n;j++)
for(int m=;m<=;m++){ //确定两个端点P[i][k]和P[j][m];接下来判断过这两点直线是否穿过所有线段;
if(P[i][k] == P[j][m]) continue;
int s;
for(s=;s<=n;s++){
if(!SegmentLineIntersection(P[i][k],P[j][m],P[s][],P[s][])) break;
}
if(s == n+) { ans = true; goto print; }
} print:
if(ans || n==) printf("Yes!\n"); //n == 1没考虑,WA了两次看discuss别人说的;
else printf("No!\n");
}
}

poj 3304 找一条直线穿过所有线段的更多相关文章

  1. POJ 3304 Segments(判断直线与线段是否相交)

    题目传送门:POJ 3304 Segments Description Given n segments in the two dimensional space, write a program, ...

  2. poj 3304 Segments(计算直线与线段之间的关系)

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10921   Accepted: 3422 Descrip ...

  3. poj 3304 判断是否存在一条直线与所有线段相交

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8579   Accepted: 2608 Descript ...

  4. POJ 1269 /// 判断两条直线的位置关系

    题目大意: t个测试用例 每次给出一对直线的两点 判断直线的相对关系 平行输出NODE 重合输出LINE 相交输出POINT和交点坐标 1.直线平行 两向量叉积为0 2.求两直线ab与cd交点 设直线 ...

  5. POJ 3304 Segments --枚举,几何

    题意: 给n条线段,问有没有一条直线,是每条线段到这条直线上的投影有一个公共点. 解法: 有公共点说明有一条这条直线的垂线过所有线段,要找一条直线过所有线段,等价于从所有线段中任选两端点形成的直线存在 ...

  6. POJ 3304 Segments【叉积】

    题意:有n条线段,问有没有一条直线使得所有线段在这条直线上的投影至少有一个共同点. 思路:逆向思维,很明显这个问题可以转化为是否有一条直线穿过所有线段,若有,问题要求的直线与该直线垂直,并且公共点为垂 ...

  7. POJ 3304 Segments(线的相交判断)

    Description Given n segments in the two dimensional space, write a program, which determines if ther ...

  8. POJ 3304 Segments(计算几何:直线与线段相交)

    POJ 3304 Segments 大意:给你一些线段,找出一条直线可以穿过全部的线段,相交包含端点. 思路:遍历全部的端点,取两个点形成直线,推断直线是否与全部线段相交,假设存在这种直线,输出Yes ...

  9. 判断线段和直线相交 POJ 3304

    // 判断线段和直线相交 POJ 3304 // 思路: // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. #include <cstdio ...

随机推荐

  1. 怎么捕获和记录SQL Server中发生的死锁

    我们知道,可以使用SQL Server自带的Profiler工具来跟踪死锁信息.但这种方式有一个很大的敝端,就是消耗很大.据国外某大神测试,profiler甚至可以占到服 务器总带宽的35%,所以,在 ...

  2. IOS 中得runloop 详细解释

    1.Runloop基础知识- 1.1 字面意思 a 运行循环 b 跑圈 - 1.2 基本作用(作用重大) a 保持程序的持续运行(ios程序为什么能一直活着不会死) b 处理app中的各种事件(比如触 ...

  3. UITableViewCell 上的按钮点击事件

     以前做tableViewCell的button点击事件,总是建立一个全局的可变数组,把data放在数组里,点击获取button的tag值,根据tag从数组了里取data. 其实,如果section只 ...

  4. 百度地图API地址转换成经纬度

    public class LngAndLatUtil { public static Map<String,Double> getLngAndLat(String address){ Ma ...

  5. SGU 145.Strange People(无环K短路)

    时间:0.25s空间:4m 题意: 其实就是求无环第K短路. 输入: 给出n,m,k,分别代表,n个点,m条边,第k长路. 接下来m行,三个整数x,y,z,分别代表x,y之间有条费用为x的双向路.保证 ...

  6. cetos 6.3 安装 apache+mysql+php

      1.安装 apache 服务器 yum install httpd 启动服务 service httpd start or /etc/init.d/httpd start 2.安装 mysql 数 ...

  7. ICE学习第一步-----配置ICE环境变量

    安装 ICE: 1.下载ICE: http://www.zeroc.com/download.html 下载说明:ICE支持语言(C++, Java, C#, Visual Basic,Python, ...

  8. <input>标签

    一. 上传图片: type="file":上传文件​ accept:选择上传的种类,图片或者是视频(/png只能上传png格式的图片) ​multiple="multip ...

  9. 定义文字用em、rem,效果和px一样

    1em=16px font-size: 2.4rem;/*2.4 × 10px = 24px*/

  10. JQuery select控件的相关操作

    JQuery获取和设置Select选项方法汇总如下: 获取select 先看看下面代码: $("#select_id").change(function(){//code...}) ...