题目:

Description

Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on it, all projected segments have at least one point in common.

Input

Input begins with a number T showing the number of test cases and then, T test cases follow. Each test case begins with a line containing a positive integer n ≤ 100 showing the number of segments. After that, n lines containing four real numbers x1 y1 x2 y2 follow, in which (x1y1) and (x2y2) are the coordinates of the two endpoints for one of the segments.

Output

For each test case, your program must output "Yes!", if a line with desired property exists and must output "No!" otherwise. You must assume that two floating point numbers a and b are equal if |a - b| < 10-8.

Sample Input

3
2
1.0 2.0 3.0 4.0
4.0 5.0 6.0 7.0
3
0.0 0.0 0.0 1.0
0.0 1.0 0.0 2.0
1.0 1.0 2.0 1.0
3
0.0 0.0 0.0 1.0
0.0 2.0 0.0 3.0
1.0 1.0 2.0 1.0

Sample Output

Yes!
Yes!
No!

题意:给出n条线段 判断是否存在一条直线 使所有线段在这条直线上的投影都有至少一个公共点
思路:经过一些奇妙的转变 可以将题目转换为从所有线段中任选两个端点组成的直线是否可以穿过所有的线段 需要对选取的两个端点进行去重

代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
const double eps=1e-;
int t,n;
double x,y,xx,yy; int dcmp(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);
}
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;
}
}line[maxn]; double xmult(Point p0,Point p1,Point p2){
return (p1-p0)^(p2-p0);
} bool Seg_inter_line(Line l1,Line l2){
return dcmp(xmult(l2.s,l1.s,l1.e))*dcmp(xmult(l2.e,l1.s,l1.e))<=;
} double dist(Point a,Point b){
return sqrt((b-a)*(b-a));
} bool check(Line l1,int n){
if(dcmp(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(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf%lf%lf",&x,&y,&xx,&yy);
line[i]=Line(Point(x,y),Point(xx,yy));
}
bool flag=false;
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(check(Line(line[i].s,line[j].s),n) || check(Line(line[i].e,line[j].e),n) || check(Line(line[i].s,line[j].e),n) || check(Line(line[i].e,line[j].s),n)){
flag=true;
break;
}
if(flag) printf("Yes!\n");
else printf("No!\n");
}
return ;
}

 

POJ 3304 Segments(直线)的更多相关文章

  1. POJ 3304 Segments[直线与线段相交]

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13514   Accepted: 4331 Descrip ...

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

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

  3. POJ 3304 Segments 判断直线和线段相交

    POJ 3304  Segments 题意:给定n(n<=100)条线段,问你是否存在这样的一条直线,使得所有线段投影下去后,至少都有一个交点. 思路:对于投影在所求直线上面的相交阴影,我们可以 ...

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

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

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

    题目链接:POJ 3304 Problem Description Given n segments in the two dimensional space, write a program, wh ...

  6. POJ 3304 Segments 基础线段交判断

    LINK 题意:询问是否存在直线,使得所有线段在其上的投影拥有公共点 思路:如果投影拥有公共区域,那么从投影的公共区域作垂线,显然能够与所有线段相交,那么题目转换为询问是否存在直线与所有线段相交.判断 ...

  7. POJ 3304 Segments (直线和线段相交判断)

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7739   Accepted: 2316 Descript ...

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

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

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

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

随机推荐

  1. 2019-04-15 python深浅复制

    原作地址:https://www.cnblogs.com/xueli/p/4952063.html 在python中,对象赋值实际上是对象的引用.当创建一个对象,然后把它赋给另一个变量的时候,pyth ...

  2. DeeplabV3+ 训练自己的遥感数据

    一.预处理数据部分 1.创建 tfrecord(修改 deeplab\ dateasets\ build_data.py) 模型本身是把一张张 jpg 和 png 格式图片读到一个 Example 里 ...

  3. GEC6818连接Ubuntu,下载程序至开发板

    使用  secure CRT连接开发板,可视化操作 连接成功 设置临时ip ubuntu 要跟 开发板同一网段: ip前三位相同 代码:sudo service tftpd-hpa restart 代 ...

  4. NTT板子

    不说别的. 这份NTT跑得比FFT快,不知道为什么. 以下代码针对\(10^5\)的数据范围. #include<cstdio> #include<vector> #inclu ...

  5. 给hMailServer添加DKIM图文教程

    https://www.hmailserver.org/viewtopic.php?f=4&t=12

  6. MyBatis基础:MyBatis调用存储过程(6)

    1. 存储过程准备 CREATE PROCEDURE sp_task ( IN userId INT ) BEGIN SELECT * FROM task WHERE user_id = userId ...

  7. springboot 静态注入 单例

    package com.b2q.web_push.util; import io.goeasy.GoEasy; import org.springframework.beans.factory.ann ...

  8. Go语言的通道(2)-缓冲通道

    有缓冲的通道相比于无缓冲通道,多了一个缓存的功能,如下图描述的一样: 从图上可以明显看到和无缓冲通道的区别,无缓冲必须两个Goroutine都进入通道才能进行数据的交换,这个不用,如果数据有,直接就能 ...

  9. lesson03

    3.1. 画 点 3.2. 基准平面 (重要) 1. 关于 点 的使用() 1.画一条直线,在线上画一个点(利用该点占该线段的百分比画出),通过该点画一条直线 2. 画一个长方体,定位到上表面.选择( ...

  10. pycharm pip安装包

    第一种方式为命令行模式,在pycharm界面按alt+F12调出命令行窗口,在窗口内输入pip install matplotlib回车即可,如图1所示 方法二:使用菜单项File——settings ...