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.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1840    题意:    判断线段是否相交  (包括间接相交)    输入:     N(代表有n条线段)     sx  sy  ex  ey(一条直线的两端点的坐标)     :     :     :     a b(判断第a条和第b条线段是否相交)     :     :      :     0 0输入0 0 询问结束     输出…
题目大意:n个人.一个区间.每个人都会在某个时间段内按相同的速度(所有人的速度都一样,都是1或-1)在他的区间内从一个端点走到另一个端点(只走一次).问每个人会与几个人碰面. 题目分析:将时间看成一个维度,区间位置看成另一个维度.那么每个人的状态便构成了一条二维线段.只需判断有几条线段与该线段相交. 判断两平面线段是否相交: 设线段1的两端点分别为A.B,线段2的两端点分别为C.D. 当两条线段平行时,只需要判断点C或点D是否在线段AB上即可.点C在线段AB上的判断:先判断向量CA与向量CB是否…
链接:传送门 题意:给出 n 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /************************************************************************* > File Name: hdu1086.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ > Created Time: 2017年05月07日 星期日 23时34…
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=648 Circuit Board Time Limit: 2 Seconds      Memory Limit: 65536 KB On the circuit board, there are lots of circuit paths. We know the basic constrain is that no two path cross each other,…
传统解法 题目来自 leetcode 335. Self Crossing. 题意非常简单,有一个点,一开始位于 (0, 0) 位置,然后有规律地往上,左,下,右方向移动一定的距离,判断是否会相交(self crossing). 一个很容易想到的方案就是求出所有线段,然后用 O(n^2) 的时间复杂度两两判断线段是否相交,而线段相交的判断,可以列个二元一次方程求解(交点).这个解法非常容易想到,但是实际操作起来比较复杂,接下去介绍利用向量的解法. 向量解法 简单回顾下向量,具体的自行谷歌.向量就…
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…
先说一下题目大意:给定一些线段,这些线段顺序编号,这时候如果两条线段相交,则把他们加入到一个集合中,问给定一个线段序号,求在此集合中有多少条线段. 这个题的难度在于怎么判断线段相交,判断玩相交之后就是怎么找个他们之间的联系,这时候就要用到并查集了. 步骤: 1.判断两条线段相交 2. 用并查集实现查找线段个数和添加到集合中 关于这个判断线段相交的问题.我搞了一晚上加上一下午,刚开始自己想了一种数学上的相交,就是先求出两条线段所在的线性方程,然后求出他们的交点,最后在判断这个交点在不在这两个线段之…
题目: 传送门 题意:在一个左小角坐标为(0, 0),右上角坐标为(10, 10)的房间里,有 n 堵墙,每堵墙都有两个门.每堵墙的输入方式为 x, y1, y2, y3, y4,x 是墙的横坐标,第一个门的区间为[ (x, y1) ~ (x, y2) ],问你从 (0, 5) 走到 (10, 5) 的最短路径是多少. 0 <= n <= 18 题解:讲每个门的端点存起来,然后,加上(0, 5) 和 (10, 5) 这两个点,暴力判断这些点两两间是否能互相直达,然后再跑一遍最短路就行了.  …
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1264 题意:中文题诶- 思路:对于直线a1a2, b1b2,我们可以通过跨立实验判断其是否相交(通过计算斜率也可以啦,不过好像有点麻烦): 其公式为:s=((向量)a1a2叉乘a1b1)*(a1a2)叉乘a1b2),若 s <=0 ,则有点b1, b2分别在线段a1a2的两边或者在同一条直线上: 我们可以很直观的知道如果a1, b2分别位于b1b2两边并且b…
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> #define N 100005 using namespace std; struct Point { double x…
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 3304 // 思路: // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #includ…
简单的计算几何题,判断两线段是否相交.将相交的两线段使用并查集归到一类中.查询时输出线段对应集合中元素的个数. #include<stdio.h> struct Point{ double x,y; }; struct Segment{ Point s,e; }node[1010]; int n,parent[1010]; int getAbs(int value) { if(value>=0)return value; return -value; } int getParent(in…
传送门:You can Solve a Geometry Problem too 题意:给n条线段,判断相交的点数. 分析:判断线段相交模板题,快速排斥实验原理就是每条线段代表的向量和该线段的一个端点与 另一条线段的两个端点构成的两个向量求叉积,如果线段相交那么另一条线段两个端点必定在该线段的两边,则该线段代表的向量必定会顺时针转一遍逆时针转一遍,叉积必定会小于等于0,同样对另一条线段这样判断一次即可. #include <algorithm> #include <cstdio>…
POJ_1066_Treasure Hunt_判断线段相交 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-art technology they are able to determine that the lower floor of the…
POJ_2653_Pick-up sticks_判断线段相交 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 the top sticks, that is these sticks such that there is no stick o…
POJ_1556_The Doors_判断线段相交+最短路 Description You are to find the length of the shortest path through a chamber containing obstructing walls. The chamber will always have sides at x = 0, x = 10, y = 0, and y = 10. The initial and final points of the path…
<题目链接> 题目大意: 给出一些线段,判断是存在直线,使得该直线能够经过所有的线段.. 解题思路: 如果有存在这样的直线,过投影相交区域作直线的垂线,该垂线必定与每条线段相交,问题转化为问是否存在一条线和所有线段相交. 如果存在这么一条直线,那么该直线一定能够移成经过两个端点的形式.枚举所有线段的两个端点,判断该直线和所有线段是否相交即可. #include <iostream> #include <math.h> #include <cstdio> us…
题目链接:http://poj.org/problem?id=1066 Time Limit: 1000MS Memory Limit: 10000K 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-art technology they are…
题目链接:http://poj.org/problem?id=2653 Time Limit: 3000MS Memory Limit: 65536K 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 the top sticks, that…
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…
题目链接 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:…
POJ2653 判断线段相交的方法 先判断直线是否相交 再判断点是否在线段上 复杂度是常数的 题目保证最后答案小于1000 故从后往前尝试用后面的线段 "压"前面的线段 排除不可能的答案 就可以轻松AC了. #include<iostream> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<algorit…
题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两端点是否在矩形内(因为是矩形,即凸多边形,直接用叉积判断即可,如果是一般的多边形,需要用射线法判断.) AC code: #include<cstdio> #include<algorithm> #include<cmath> #include<cstdlib>…
题目链接: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<…
题目大意: 询问给定n条线段 是否存在一条直线使得所有线段在直线上的投影存在公共点 这个问题可以转化为 是否存在一条直线与所有的线段同时相交 而枚举直线的问题 因为若存在符合要求的直线 那么必存在穿过某线段的端点的直线是符合要求的直线 那么只要枚举两个端点连成一线 #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> using namespace std; ;…
题目传送门:POJ 3304 Segments 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. Inp…
POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const double eps = 1e-8;…