poj1410 Intersection

图神经网络实战(2)——图论基础 图论 (Graph theory) 是数学的一个基本分支,涉及对图研究。图是复杂数据结构的可视化表示,有助于理解不同实体之间的关系。图论提供了大量建模和分析现实问题的工具,如交通系统、社交网络和互联网等。在本节中,将介绍图论的基本原理,主要涉及三个方面:图属性、图概念和图算法。 阅读详情

Intersection
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 10675 Accepted: 2807

Description

You are to write a program that has to decide whether a given line segment intersects a given rectangle. 

An example: 
line: start point: (4,9) 
end point: (11,2) 
rectangle: left-top: (1,5) 
right-bottom: (7,1) 

 
Figure 1: Line segment does not intersect rectangle 

The line is said to intersect the rectangle if the line and the rectangle have at least one point in common. The rectangle consists of four straight lines and the area in between. Although all input values are integer numbers, valid intersection points do not have to lay on the integer grid. 

Input

The input consists of n test cases. The first line of the input file contains the number n. Each following line contains one test case of the format: 
xstart ystart xend yend xleft ytop xright ybottom 

where (xstart, ystart) is the start and (xend, yend) the end point of the line and (xleft, ytop) the top left and (xright, ybottom) the bottom right corner of the rectangle. The eight numbers are separated by a blank. The terms top left and bottom right do not imply any ordering of coordinates.

Output

For each test case in the input file, the output file should contain a line consisting either of the letter "T" if the line segment intersects the rectangle or the letter "F" if the line segment does not intersect the rectangle.

Sample Input

1
4 9 11 2 1 5 7 1

Sample Output

F

Source



判断矩形和线段是否相交,没什么说的,只是写的好别扭……

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

#define eps 1e-6

struct Point
{
    double x,y;
    Point(double xx,double yy)
    {
        x=xx;y=yy;
    }
    Point(){}
};

struct Obj
{
    Point begin,end;
    Obj(Point begin1,Point end1)
    {
        begin=begin1;
        end=end1;
    }
    Obj(){}
};

bool Check(Point p,Obj rec)
{
    if (p.x<=max(rec.begin.x,rec.end.x) && p.x>=min(rec.begin.x,rec.end.x) && p.y<=max(rec.begin.y,rec.end.y) && p.y>=min(rec.begin.y,rec.end.y)) return true;
    return false;
}

double mul(Obj line1,Obj line2)
{
    return (line1.end.x-line1.begin.x)*(line2.end.y-line2.begin.y)-(line2.end.x-line2.begin.x)*(line1.end.y-line2.begin.y);
}

bool cross(Obj line1,Obj line2)
{
    if (min(line1.begin.x,line1.end.x)>max(line2.begin.x,line2.end.x)) return false;
    if (min(line2.begin.x,line2.end.x)>max(line1.begin.x,line1.end.x)) return false;
    if (min(line1.begin.y,line1.end.y)>max(line2.begin.y,line2.end.y)) return false;
    if (min(line2.begin.y,line2.end.y)>max(line1.begin.y,line1.end.y)) return false;
    Obj tmp1(line1.begin,line2.begin),tmp2(line1.begin,line2.end);
  //  printf("%f~~\n",mul(line1,tmp1)*mul(line1,tmp2));
    if (mul(line1,tmp1)*mul(line1,tmp2)>eps) return false;
    Obj tmp3(line2.begin,line1.begin),tmp4(line2.begin,line1.end);
    if (mul(line2,tmp3)*mul(line2,tmp4)>eps) return false;
    return true;
}

bool Inter(Obj line,Obj rec)
{
    Point p1(rec.begin.x,rec.begin.y),p2(rec.begin.x,rec.end.y),p3(rec.end.x,rec.end.y),p4(rec.end.x,rec.begin.y);
    Obj line1(p1,p2),line2(p2,p3),line3(p3,p4),line4(p4,p1);
    if (cross(line,line1) || cross(line,line2) || cross(line,line3) || cross(line,line4)) return true;
    return false;
}

int main()
{
    int i,j,n,T;
    Obj rec,line;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&line.begin.x,&line.begin.y,&line.end.x,&line.end.y,&rec.begin.x,&rec.begin.y,&rec.end.x,&rec.end.y);
        bool x=Check(line.begin,rec);
        bool y=Check(line.end,rec);
      //  printf("%d %d\n",x,y);
        if (x || y)
        {
            printf("T\n");
            continue;
        }
        if (Inter(line,rec))
        {
            printf("T\n");
        }
        else
        {
            printf("F\n");
        }
    }
    return 0;
}


Windows Server 2016远程桌面服务配置和授权激活 Server 2016默认远程桌面连接数是2个用户,如果多余两个用户进行远程桌面连接时,系统就会提示超过连接数,可以通过添加远程桌面授权解决:1、添加远程桌面授权服务第一步:服务器管理 - 添加角色和功能打开添加角色和功能向导窗口,选择基于角色或给予功能安装:第二步:添加远程桌面会话主机和远程桌面授权功能:以上配置完成后即可使用多于2用户同时登陆,但使用期限为120天,再次登陆会有如下提示:2、添... 阅读详情

相关推荐

从晶体管到触发器:为什么芯片设计必须区分同步/异步复位?

本文深入探讨了芯片设计中同步复位与异步复位的物理本质与工程权衡。从晶体管级的CMOS结构出发,剖析了两种复位方式在物理实现、时序可靠性(如建立/保持时间、恢复/移除时间)上的根本差异,并分析了在不同应用场景下的选择策略。文章强调,理解复位信号的底层机制对于确保芯片时序收敛、系统上电确定性及整体鲁棒性至关重要。

time3的博客 229

poj1410 - Intersection

想看更多的解题报告:http://blog.csdn.net/wangjian8006/article/details/7870410                                   转载请注明出处:http://blog.csdn.net/wangjian8006 题目大意:题目意思很简单,就是说有一个矩阵是实心的,给出一条线段,问线段和矩阵是否相交 解题思路:用到

贰圣 2188

MODTRAN5.2.1安装配置

MODTRAN5.2.1安装配置

Home 4352

POJ1410 Intersection

原题传送门:http://poj.org/problem?id=1410 博主的中文题面(放心提交): https://www.luogu.org/problemnew/show/T22919 Intersection Description You are to write a program that has to decide whether a given l...

ShadyPi的IT笔记 397

【GD32篇】驱动AD7616完成数据采集

GD32F10X驱动AD7616完成数据采集

we_long的博客 1万+

群晖NAS从入门到精通的所有帖子汇总,只要这一篇就够了

本站陆陆续续的转载、原创帖子也有十几二十篇了,从不同的角度对群晖NAS的各种骚操作都有深入的讲解,虽然很多文章都不是讲的很深入,但是针对小白入门已经是足够了,希望对小白来说是一个入门,群晖NAS的大佬们勿喷,哪里写的不对的,请随时留言西安SEO优化站长一定在第一时间纠正修改。

西安SEO优化网站资源 8万+

poj1410 Intersection 线段与矩形相交

//poj1410 //题目意思:判断线段是否与矩形相交(注:线段在矩形内也是相交) //解题思路:图形学中的线段裁剪算法,有Cohen-Sutherland,梁友栋-Barsky等, //这里用容易理解的方法:先判断是否有一个点在矩形内,若都没有再去判断4条边与线段是否相交 //0ms AC 代码如下: #include&lt;iostream&gt; #include&lt...

java开发指南博客 【转载】 266

告别手动拍照!用Python+JAKA机械臂+D455相机实现全自动手眼标定(附完整代码)

本文详细介绍了如何利用Python脚本实现JAKA机械臂与Intel RealSense D455相机的全自动手眼标定流程,提供从硬件配置到代码实现的完整解决方案。通过自动化标定,显著提升工业自动化中的精度和效率,适用于机器人视觉领域的二次开发需求。

weixin_30555125的博客 536

poj1410——Intersection

大致题意:就是判断矩形有没有和线段相交的水题,等等,为什么别人说还要判断是不是在矩形内???但是我没判断啊???我怎么就过了????可能是数据水吧,其实判断线段在不在矩形内也很简单,大不了就多一点点代码量判断一下。算了,不添了,就当是生活给的一点小乐趣吧。 最后,代码: #include<iostream> using namespace std; struct line { ...

qq_43141496的博客 228

ADS2019学习笔记:三、SPICE model导入

以BZX84-C33 SPICE model为例,学习如何在ADS2019中导入SPICE model。

qq_42945911的博客 6512

Parasoft C++Test软件集成测试(部件测试)_实例讲解

本文以一组功能函数组件作为示例,讲解了如何使用C++Test进行软件集成测试。本文的示例比较简单,但是思路、方法和流程都是通用的,希望对大家有所帮助。

文章主要涉及嵌入式软件开发、测试、项目管理等,欢迎交流,共同进步。 749

POJ 1410 Intersection

POJ 1410 Intersection Description You are to write a program that has to decide whether a given line segment intersects a given rectangle. An example: line: start point: (4,9) end point: (11,2) rectan...

旺崽的博客 2999

INCA ProF文件解析

本博文从实际应用出发,介绍INCA prof文件的关键信息,通过实例,描述当得到一个刷写需求后,如何在不改变用户之前的使用习惯的前提下,满足原有的INCA刷写应用数据和标定程序的需求。 声明:本文不涉及项目名称,没有商业目的,纯属分享技术,乐享知识。

汽车电子软件领域知识分享 1万+

POJ 1410 Intersection(数据小坑,线段相交)

思路:这道题的数据有点问题,不是严格的按照左上右下给的矩阵坐标,所以要自己进行一个特判,之后就是判断线段是否相交了。

weixin_48024524的博客 230

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Poj-1410-Intersection

Description You are to write a program that has to decide whether a given line segment intersects a given rectangle.  An example:  line: start point: (4,9)  end point: (11,2)  rectangle: left-top

yeyun666的博客 483

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Intersection POJ - 1410

Intersection POJ - 1410 分类:计算几何+线段相交 题目: You are to write a program that has to decide whether a given line segment intersects a given rectangle. An example: line: start point: (4,9) end poi...

DeathYmz的博客 639

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

poj 1410 Intersection

题目来源:POJ 1410 简单题目分析: 求线段和矩形是否相交,注意在本题中,如果线段在矩形内部也视作相交。 思路: 1. 如果线段的两个端点都在矩形内,那么相交。 2. 如果线段的两个端点,一个在内部,一个在外部,那么相交。 注意,这两种情况包含端点在矩形边界的特殊情况。 稍微复杂一些的是,如果两个端点都不在矩形内部,那么分类讨论: 首先是两种特殊情况,斜率为0和斜率不存在的情

Polanwind 342

poj 1410 Intersection

题目地址:poj1410 判断线段和矩形区域是否有公共点。 1 和线段系相交 2 线段在矩形内部 其中有公共点也算是相交 不一定是规范相交。 非规范相交的模板先写错了。并不是直接把两个 应该在两线段共线

Jingqi@Mr.B的ACM博客 588

POJ 1410 Intersection

判断线段与多边形是否相交。 模板: #include #include #include using namespace std; #define Pi 3.14159265358979 #define PRECISION 1e-8 //点 typedef struct { double x,y; } POINT; //直线两点的表达 struct LINE{

ljd4305的专栏 956
上一篇: poj1470 Closest Common Ancestors
下一篇: poj1386 Play on Words
magicnumber
博客等级 码龄18年 119粉丝 196原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址