typedef struct double x y Point int dblcmpdouble
二维平面内线段规范相交的判定 代码实现 typedef struct { double x, y; } Point; int dblcmp(double d) { if (fabs(d) < precision) return 0; return (d > 0) ? 1 : -1; } double det(double x 1, double y 1, double x 2, double y 2) { return x 1 * y 2 - x 2 * y 1; } double cross(Point a, Point b, Point c) { return det(b. x - a. x, b. y - a. y, c. x - a. x, c. y - P a. y); } int segcross. Simple(Point a, Point b, Point c, Point d) { return (dblcmp(cross(a, c, d)) ^ dblcmp(cross(b, c, d))) == -2 && (dblcmp(cross(c, a, b)) ^ dblcmp(cross(d, a, b))) == -2; P 1 } n P 2 P’
二维平面内线段非规范相交的判定 代码实现 // ab与cd: 0 - 不相交; 1 - 规范相交; 2 - 不规范相交 int segcross(Point a, Point b, Point c, Point d) { int d 1, d 2, d 3, d 4; d 1 = dblcmp(cross(a, b, c)); d 2 = dblcmp(cross(a, b, d)); d 3 = dblcmp(cross(c, d, a)); d 4 = dblcmp(cross(c, d, b)); if (d 1 == 0 && between. Cmp(c, a, b) <= 0 || d 2 == 0 && between. Cmp(d, a, b) <= 0 || d 3 == 0 && between. Cmp(a, c, d) <= 0 || d 4 == 0 && between. Cmp(b, c, d) <= 0) return 2; return 0; } n
二维平面内线段非规范相交的判定 代码实现(续) // 判断a是否在bc范� 内 int between. Cmp(Point a, Point b, Point c) { if (fabs(b. x - c. x) > fabs(b. y - c. y)) return xy. Cmp(a. x, min(b. x, c. x), max(b. x, c. x)); else return xy. Cmp(a. y, min(b. y, c. y), max(b. y, c. y)); } int xy. Cmp(double p, double mini, double maxi) { return dblcmp(p - mini) * dblcmp(p - maxi); } n
线段相交的应用 n n n POJ 1066 《Treasure Hunt》 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 pyramid is constructed from a series of straightline walls, which intersect to form numerous enclosed chambers. Currently, no doors exist to allow access to any chamber. This state-of-the-art technology has also pinpointed the location of the treasure room. What these dedicated (and greedy) archeologists want to do is blast doors through the walls to get to the treasure room. However, to minimize the damage to the artwork in the intervening chambers (and stay under their government grant for dynamite) they want to blast through the minimum number of doors. For structural integrity purposes, doors should only be blasted at the midpoint of the wall of the room being entered. You are to write a program which determines this minimum number of doors. An example is shown below:
线段相交的应用 n n The input will consist of one case. The first line will be an integer n (0 <= n <= 30) specifying number of interior walls, followed by n lines containing integer endpoints of each wall x 1 y 1 x 2 y 2. The 4 enclosing walls of the pyramid have fixed endpoints at (0, 0); (0, 100); (100, 100) and (100, 0) and are not included in the list of walls. The interior walls always span from one exterior wall to another exterior wall and are arranged such that no more than two walls intersect at any point. You may assume that no two given walls coincide. After the listing of the interior walls there will be one final line containing the floating point coordinates of the treasure in the treasure room (guaranteed not to lie on a wall). Print a single line listing the minimum number of doors which need to be created, in the format shown below.
凸包的应用-POJ 1113《Wall》 n Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall.
凸包的应用-POJ 1113《Wall》 n n Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements. The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.
凸包的应用-POJ 1113《Wall》 n n n INPUT The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle. Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.
凸包的应用-POJ 1113《Wall》 n n OUTPUT Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.
讨论题 n n n POJ 1873 POJ 2932 POJ 1556 POJ 1031 POJ 1271 POJ 1418 POJ 1654 POJ 1687 POJ 1688 POJ 1696 POJ 1758
- Slides: 53