题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两端点是否在矩形内(因为是矩形,即凸多边形,直接用叉积判断即可,如果是一般的多边形,需要用射线法判断.) AC code: #include<cstdio> #include<algorithm> #include<cmath> #include<cstdlib>…
http://poj.org/problem?id=1410 题目大意:给你一个线段和矩形的对角两点  如果相交就输出'T'  不想交就是'F' 注意: 1,给的矩形有可能不是左上 右下  所以要先判断的 2,线段在矩形的内部输出T 3,如果交点是矩形的顶点的话 是不相交的 情况有点多  刚开始考虑的太少   wa的我心疼 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.…
题目链接 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12040   Accepted: 3125 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:…
Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9996   Accepted: 2632 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) …
Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16322   Accepted: 4213 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)…
题目大意:给一个线段和一个矩形,判断线段是否和矩形有公共点.   分析:用矩形的四个边当线段判断与所给的线段是否有交点,需要注意的是给的矩形是不标准的,需要自己转换,还需要注意线段有可能在矩形内部.   代码如下: ==============================================================================================================================================…
这个题目要注意的是:给出的矩形坐标不一定是按照左上,右下这个顺序的 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define eps 1e-8 #define INF 1e9 using namespace std; const int maxn=100; typedef struct Point {…
题目链接:http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12822   Accepted: 3347 Description You are to write a program that has to decide whether a given line segment intersects a given rectangle.…
题目: 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 doe…
题意: 给一条线段,和一个矩形,问线段是否与矩形相交或在矩形内. 解法: 判断是否在矩形内,如果不在,判断与四条边是否相交即可.这题让我发现自己的线段相交函数有错误的地方,原来我写的线段相交函数就是单纯做了两次跨立实验,在下图这种情况是错误的: 这样的话线段与右边界的两次跨立实验(叉积<=0)都会通过,但是并不相交. 所以要加快速排斥. 还有就是这题题目说给出的不一定是左上角,右下角依次的顺序.所以干脆重新自己定义左上角,右下角. 代码: #include <iostream> #inc…
题目大意:RT 分析:构造一条射线,如果穿越偶数条边,那么就在多边形外面,如果穿越奇数条边,那么就在多边形里面. 代码如下: =========================================================================================================================== #include<stdio.h> #include<algorithm> #include<string…
/** http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1840    题意:    判断线段是否相交  (包括间接相交)    输入:     N(代表有n条线段)     sx  sy  ex  ey(一条直线的两端点的坐标)     :     :     :     a b(判断第a条和第b条线段是否相交)     :     :      :     0 0输入0 0 询问结束     输出…
先说一下题目大意:给定一些线段,这些线段顺序编号,这时候如果两条线段相交,则把他们加入到一个集合中,问给定一个线段序号,求在此集合中有多少条线段. 这个题的难度在于怎么判断线段相交,判断玩相交之后就是怎么找个他们之间的联系,这时候就要用到并查集了. 步骤: 1.判断两条线段相交 2. 用并查集实现查找线段个数和添加到集合中 关于这个判断线段相交的问题.我搞了一晚上加上一下午,刚开始自己想了一种数学上的相交,就是先求出两条线段所在的线性方程,然后求出他们的交点,最后在判断这个交点在不在这两个线段之…
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…
Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7857   Accepted: 3247 Description Archeologists from the Antiquities and Curios Museum (ACM) have flown to Egypt to examine the great pyramid of Key-Ops. Using state-of-the-ar…
题目链接:https://vjudge.net/problem/POJ-1556 题意:在一个矩形内,起点(0,5)和终点(10,5)是固定的,中间有n个道墙(n<=18),每道墙有两个門,求起点到终点的最短路. 思路: 最多有4*n+2个点,枚举所有点对(p1,p2),用叉积判断线段p1p2和中间的墙是否相交,不相交那么更新距离为两点的距离,否则为inf.更新所有的边之后用floyd得到最短路.答案即dist[0][4*n+1].时间复杂度O(n^3). AC code: #include<…
直接用kuangbin的板子,能判不规范,规范和不交 另外线段在矩形内也可以,判断方式是比较线段的端点和矩形四个角 #include <cstdio> #include <cmath> #include <algorithm> #include <iostream> using namespace std; ; ; )?:-;} struct Point{ double x,y; Point(,):x(_x),y(_y){} bool operator ==…
在编写图形界面软件的时候,经常会遇到处理两个矩形的关系. 如图[1.jpg]所示,矩形的交集指的是:两个矩形重叠区的矩形,当然也可能不存在(参看[2.jpg]). 两个矩形的并集指的是:能包含这两个矩形的最小矩形,它一定是存在的. 本题目的要求就是:由用户输入两个矩形的坐标,程序输出它们的交集和并集矩形. 矩形坐标的输入格式是输入两个对角点坐标,注意,不保证是哪个对角, 也不保证顺序(你可以体会一下,在桌面上拖动鼠标拉矩形,4 个方向都可以的). 输入数据格式: x1,y1,x2,y2 x1,y…
传统解法 题目来自 leetcode 335. Self Crossing. 题意非常简单,有一个点,一开始位于 (0, 0) 位置,然后有规律地往上,左,下,右方向移动一定的距离,判断是否会相交(self crossing). 一个很容易想到的方案就是求出所有线段,然后用 O(n^2) 的时间复杂度两两判断线段是否相交,而线段相交的判断,可以列个二元一次方程求解(交点).这个解法非常容易想到,但是实际操作起来比较复杂,接下去介绍利用向量的解法. 向量解法 简单回顾下向量,具体的自行谷歌.向量就…
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> #define N 100005 using namespace std; struct Point { double x…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1558 解题报告:首先如果两条线段有交点的话,这两条线段在一个集合内,如果a跟b在一个集合内,b跟c在一个集合内,那么a跟c在一个集合内.在一个平面上,有两种操作: P:在这个平面上添加一条线段 Q k:询问添加的第k条线段所在的那个集合有多少条线段 用并查集,然后就是要判断一下线段有没有交点.还有就是题目要求两个test之间要有空行,为此我还PE了一次. #include<cstdio> #inc…
<zw版·Halcon-delphi系列原创教程> Halcon分类函数005·graphics-obj,基本绘图单元,包括线段.矩形.椭圆.圆形 graphics-obj,基本绘图单元,包括线段.矩形.椭圆.圆形 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“procedure” :: 用大写字母“X”,替换:“IHUntypedObjectX” :: 省略了字符:“const”.“OleVariant” [示例] 说明 函数: procedure…
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1264 三角形的有向面积:a.x*b.y+b.x*c.y+c.x*a.y - a.x*c.y - c.x*b.y - b.x*a.y; 上面得到的即是以点A,B,C三点组成的三角形面积的两倍. 如果area >0 则点A,B,C呈逆时针排列. 如果area<0  则点A,B,C呈顺时针排列. 如果area=0  则点A,B,C三点共线. 那么判断线段1(两个端点poin…
Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 7699   Accepted: 2843 Description Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find…
// 线段和矩形相交 POJ 1410 // #include <bits/stdc++.h> #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> #include <math.h> using namespace std; #define LL long long typedef p…
// 判断线段和直线相交 POJ 3304 // 思路: // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #includ…
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11353 #include<iostream> #include<stdio.h> #include<string> #include<math.h> #define PI acos(-1) //using namespace std; struct Nod { int dir; int len; }node[]; str…
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D 改了N多次之后终于A了,一直在改判断正方形和矩形那,判断正方形时算出六条边再排序,若前四条边相等并且与后两条边满足勾股定理,说明是正方形, 判断矩形时,我先对结构体二级排序,这样四个点有确定的顺序,再用点积判断是否有三个角是直角,是的话就是矩形. #include<stdio.h> #include<string.h> #include&l…
Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10330   Accepted: 3833 Description Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to fin…
Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are parallel with the X-axis, and the other two are parallel with the Y-axis), you have to tell if their borders intersect. Note: we call them intersect ev…