
计算几何
文章平均质量分 79
synapse7
这个作者很懒,什么都没留下…
展开
-
LightOJ 1203 Guarding Bananas (凸包最小顶角)
http://lightoj.com/volume_showproblem.php?problem=1203/*0.164s,6512KB*/#includeusing namespace std;#define sqr(x) ((x)*(x))const double INF = 1e100;const double pi = acos(-1.0);const doub原创 2014-03-26 17:52:26 · 1487 阅读 · 0 评论 -
POJ 1265 Area (Pick定理&多边形面积)
http://poj.org/problem?id=1265定理证明见Matrix67——最酷的证明:Pick定理另类证法注意dx和dy是机器人下一步移动的方向,所以位置要累加。完整代码:/*0ms,372KB*/#include#includeconst int mx = 105;struct point{ double x, y; point(原创 2014-02-13 20:19:32 · 967 阅读 · 0 评论 -
POJ 1654 Area (多边形面积)
http://poj.org/problem?id=1654用整数即可。/*16ms,916KB*/#includeconst int dx[] = { -1, 0, 1, -1, 0, 1, -1, 0, 1};const int dy[] = { -1, -1, -1, 0, 0, 0, 1, 1, 1};char s[1000005];int main原创 2014-02-13 20:52:53 · 1686 阅读 · 0 评论 -
POJ Space Ant (向量夹角)
http://poj.org/problem?id=1696水。求出最大余弦值即可。完整代码:/*0ms,548KB*/#include#include#includedouble x[55], y[55], dx, dy;bool vis[55];///单位化向量inline void dentity_vector(double nowx, dou原创 2014-02-13 14:20:07 · 899 阅读 · 0 评论 -
ACM计算几何题目推荐(第二期)
这次推荐的题目比上次难了,也复杂多了。PS:下面的OJ之中,CII是指ACM-ICPC Live Archive ,网址是:http://cii-judge.baylor.edu/一。基础题目1.1 有固定算法的题目A, 最近点对问题最近点对问题的算法基于扫描线算法。ZOJ 2107 Quoit Design 典型最近点对问题POJ转载 2014-02-13 11:48:06 · 1307 阅读 · 0 评论 -
UVa 10902 / POJ 2653 Pick-up Sticks (线段与线段相交)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1843http://poj.org/problem?id=2653思路:枚举即可,注意是“任意时刻”没有超过1000个top sticks,要不然最坏复杂度就是O(n^2)了。原创 2014-02-12 13:51:40 · 1908 阅读 · 0 评论 -
POJ 3304 Segments (判断直线和线段是否相交)
思路:若所有线段在直线l上的投影有公共点p,那我们可以形象地说,(由投影的定义)必有一束细光穿过所有线段,投到直线l上,且在之上形成了一个光点p。那么,是否有这么一束光呢?如何求呢?方法:枚举两两线段的各一个端点,连一条直线,再判断剩下的线段是否都和这条直线有交点。证明:为什么只需每次枚举两个端点就行了呢?首先假设这条直线不过任何端点,则我们可以左右平移这条直线,直到“脱离”了某个线段原创 2014-02-10 16:48:39 · 1487 阅读 · 0 评论 -
POJ 2187 Beauty Contest (凸包&最远点距&旋转卡壳)
http://poj.org/problem?id=2187思路:算出凸包后枚举凸包上的点。复杂度为O(NlogN+M)为什么可以枚举?设坐标的绝对值不超过M,则凸包至多有O(√M)个顶点证明:以(0,0)为起点画出如下“极限凸包”(0,0)-(1,0)-(2,1)-(3,3)-(4,6)-...当x每次只增加1时,y增加速率是平方级的,所以凸包至多有O(√M)个顶原创 2014-02-14 11:10:18 · 1172 阅读 · 0 评论 -
POJ 2079 Triangle (凸包中的最大三角形&旋转卡壳)
O(N^3)枚举肯定不行,但是我们换个思路,可以得到一个O(3N)的线性“枚举”算法(旋转卡壳)怎么做?令i=0,j=1,k=2,这是我们最开始的三角形,然后不断放大这个三角形:先放大k至面积最大,再放大j至面积最大,再放大i至面积最大。由于叉积的良好性质,在放大的过程中保证i<j<k。这样因为每个点至多被经过3次,所以复杂度是O(3N)的。原创 2014-02-14 13:02:13 · 1674 阅读 · 1 评论 -
POJ 2954 Triangle (Pick定理)
http://poj.org/problem?id=2954完整代码:/*0ms,356KB*/#include#include#includeint x[4], y[4];int gcd(int a, int b){ return b ? gcd(b, a % b) : a;}double s(){ double ret = 0.0; for (i原创 2014-02-13 20:37:09 · 842 阅读 · 0 评论 -
UVa 10263 Railway (点到线段的最短距离)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1204/*0.016s*/#includeusing namespace std;double eps = 1e-10;struct P{ double x原创 2014-02-17 10:50:14 · 1433 阅读 · 0 评论 -
UVa 109 SCUD Busters (凸包面积&判断点是否在凸包内部)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=45套模板即可。一道类似的题:LightOJ 1190 Sleepwalking完整代码:/*0.018s*/#includeusing namespace s原创 2014-02-14 22:25:23 · 1164 阅读 · 0 评论 -
HDU 4741 Save Labman No.004 (异面直线距离&直线与平面的交点)
http://acm.hdu.edu.cn/showproblem.php?pid=4741模板题。理论知识见代码注释。这题背景居然是命运石之门。。/*218ms,276KB*/#include#includeconst double eps = 1e-9;struct P3{ double x, y, z; P3(double x = 0.0, do原创 2014-03-16 19:20:13 · 1290 阅读 · 0 评论 -
POJ 2932 Coneology (扫描线判断最外面的圆&set维护最近的圆)
http://poj.org/problem?id=2932先给圆的最左端和最右端的点排个序,当两点x相同时,左端点排在前面。然后就是扫描了,若扫描到的是圆的左端点,就判断圆心(y坐标)在其上方且离其最近的圆是否包含此圆,以及圆心(y坐标)在其下方且离其最近的圆是否包含此圆,若包含就continue,不包含就insert到set中;若扫描到的是圆的右端点,就从set中era原创 2014-03-20 15:08:49 · 1180 阅读 · 0 评论 -
UVa 11178 Morley's Theorem (向量旋转)
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2119/*0.025s*/#include#includestruct P{ double x, y; P(double x = 0.0, double y = 0.0): x(x), y(y) {} v原创 2014-03-27 16:35:30 · 1555 阅读 · 0 评论 -
Codeforces Round #198 (Div. 2) / 340B Maximal Area Quadrilateral (点集中的最大四边形)
http://codeforces.com/contest/340/problem/B枚举一条线段,再枚举这条线段左右两边的三角形,拼起来就是一个四边形了。完整代码:/*186ms,0KB*/#includeusing namespace std;int x[300], y[300], A[2];int main(){ int n, i, j, k,原创 2014-03-14 14:19:20 · 1208 阅读 · 0 评论 -
ZOJ 3762 Pan's Labyrinth (点集中的最大点-线距&技巧性枚举)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3762思路:(转自这篇文章)假设拥有最大高的三角形是ABC,如下图结合此图我们可以看出最大高是点C到直线AB,在这种情况下,下列两个假设至少有一个成立1.点C是所有点中距离点A最远的2.点C是所有点中距离点B最远的反证:(这里先证明在AB上侧成立的情况原创 2014-03-10 18:59:17 · 1751 阅读 · 2 评论 -
UVa 10577 Bounding box (直线交点&正多边形中心)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1518先由给出的三个点画两条中垂线求交点——正多边形的中心,然后用点的旋转求边界上的所有点,随后求出矩形边界。完整代码:/*0.018s*/#inclu原创 2014-03-06 20:59:30 · 1316 阅读 · 0 评论 -
POJ 1127 Jack Straws (线段不规范相交&&图的连通性&&Floyd-Warshall算法)
http://poj.org/problem?id=1127/*16ms,376KB*/#include#includestruct P{ int x, y; P(int x = 0, int y = 0): x(x), y(y) {} P operator + (P p) { return P(x + p.x, y + p.y); } P operator原创 2014-02-15 01:50:22 · 1155 阅读 · 0 评论 -
POJ 1912 A highway and the seven dwarfs (凸包&O(logN)判断直线是否与凸包相交)
http://poj.org/problem?id=1912思路:构造好凸包后,二分找凸包上第一个与正向直线夹角大于0的线段和第一个与反向直线夹角大于0的线段然后判断两线段的起点是否在直线两侧即可。完整代码:/*2672ms,4624KB*/#include#include#includeusing namespace std;const double原创 2014-02-22 21:33:24 · 2731 阅读 · 1 评论 -
POJ 3348 Cows (凸包面积)
http://poj.org/problem?id=3348水。完整代码:/*0ms,680KB*/#include#include#includeusing namespace std;const double eps = 1e-8;const int mx = 10005;struct point{ double x, y; point(do原创 2014-02-13 18:26:08 · 904 阅读 · 0 评论 -
UVa 10002 Center of Masses (凸包重心)
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=943重心=(多边形三角剖分的各个三角形的重心*各个三角形的有向面积/多边形面积)/3完整代码:/*0.095s*/#includeusing namespace std;const int mx =原创 2014-02-14 14:03:19 · 1399 阅读 · 0 评论 -
UVa 143 Orchard Trees (数学&计算几何&枚举)
143 - Orchard TreesTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=79An Orchardist has planted an orchard in a rectang原创 2013-09-27 19:21:06 · 1438 阅读 · 0 评论 -
POJ 2606 / URAL 1502 Rabbit hunt (计算几何)
1052. Rabbit HuntTime limit: 1.0 secondMemory limit: 64 MBA good hunter kills two rabbits with one shot. Of course, it can be easily done since for any two points we can always draw a li原创 2013-09-21 06:37:00 · 1479 阅读 · 0 评论 -
UVa 375 Inscribed Circles and Isosceles Triangles (等腰三角形内切圆&规律)
375 - Inscribed Circles and Isosceles TrianglesTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=101&page=show_problem&problem=311Given two原创 2013-10-01 22:17:24 · 1225 阅读 · 0 评论 -
最酷的证明:Pick定理另类证法
难以想像,一段小小的证明竟然能比一个瘦小的留着长头发穿黑色短袖T恤紧身牛仔裤边跳边弹吉他的MM还要酷。原来一直以为这个证明已经很酷了,现在显然我已经找到了一个更酷的证明。 Pick定理是说,假设平面上有一个顶点全在格点上的多边形P,那么其面积S(P)应该等于i+b/2-1,其中i为多边形内部所含的格点数,b是多边形边界上的格点数。绝大多数证明都是用割补的办法重新拼拆多边形。这里,我们来看转载 2013-10-04 21:36:17 · 1093 阅读 · 0 评论 -
UVa 10387 Billiard (计算几何&反射)
10387 - BilliardTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=101&page=show_problem&problem=1328In a billiard table with horizontal sid原创 2013-10-01 23:27:30 · 1363 阅读 · 0 评论 -
UVa 10112 Myacm Triangles (枚举&计算几何)
10112 - Myacm TrianglesTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=101&page=show_problem&problem=1053There has been considerabl原创 2013-10-01 15:49:53 · 1179 阅读 · 0 评论 -
UVa 10250 The Other Two Trees (计算几何)
10250 - The Other Two TreesTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=101&page=show_problem&problem=1191You have a quadrilateral s原创 2013-10-01 16:43:25 · 1183 阅读 · 0 评论 -
Codeforces Beta Round #21 / 21B Intersection(数学&详细分情况)
B. Intersectionhttp://codeforces.com/problemset/problem/21/Btime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output原创 2013-08-13 16:48:52 · 1337 阅读 · 0 评论 -
POJ 2242 The Circumference of the Circle (计算几何)
The Circumference of the Circlehttp://poj.org/problem?id=2242Time Limit: 1000MSMemory Limit: 65536KDescriptionTo calculate the circumference of a circle seems to be an easy原创 2013-09-28 21:27:28 · 2157 阅读 · 1 评论 -
UVa 190 Circle Through Three Points (求不共线三点所确定的圆的方程)
190 - Circle Through Three PointsTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=126The solution is to be printed as an equation of原创 2013-10-19 22:50:52 · 2428 阅读 · 0 评论 -
POJ 1113 Wall (凸包周长)
http://poj.org/problem?id=1113使用Graham-Scan算法。为什么扫描阶段的复杂度是O(n)的?因为在扫描的过程中,每个点至多进栈一次,至多出栈一次,也就是说对每个点我们至多进行两次叉积运算,所以复杂度是O(n)的。完整代码:/*16ms,592KB*/#include#include#includeusing name原创 2014-02-13 17:52:22 · 909 阅读 · 0 评论 -
POJ 2318 TOYS + POJ 2398 Toy Storage (点与直线的位置关系)
http://poj.org/problem?id=2318利用向量外积+lower_bound搞定,见代码。/*172ms,484KB*/#include#include#includeusing namespace std;const int mx = 5005;struct point{ int x, y; point() {} point(int原创 2014-02-09 15:44:31 · 795 阅读 · 0 评论 -
UVa 270 / POJ 1118 Lining Up (计算几何)
270 - Lining UpTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=206``How am I ever going to solve this pro原创 2013-09-20 23:13:36 · 1662 阅读 · 0 评论 -
Codeforces Round #100 / 140A (简单几何)
http://codeforces.com/contest/140/problem/A过大圆圆心作小圆切线即可发现规律,详见代码。注意判相等一定要用fabs!!!完整代码:/*30ms,0KB*/#includeusing namespace std;int main(){ int n, R, r; double a; scanf("%d%d%d"原创 2013-12-08 15:31:03 · 1284 阅读 · 5 评论 -
UVa 10545 Maximal Quadrilateral (有内切圆的四边形面积)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1486公式参考维基百科完整代码:#include#includeint main(){ int t, cas = 0, p, a, b; d原创 2013-12-06 22:26:43 · 932 阅读 · 0 评论 -
UVa 10245 The Closest Pair Problem (计算几何&最近点对)
10245 - The Closest Pair ProblemTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1186Given a set of points原创 2013-09-20 13:00:45 · 1242 阅读 · 0 评论 -
POJ 1835 宇航员 (模拟&三维向量旋转)
宇航员http://poj.org/problem?id=1835Time Limit: 2000MSMemory Limit: 30000KDescription问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下原创 2013-10-24 00:23:07 · 3160 阅读 · 0 评论 -
UVa 438 The Circumference of the Circle (计算几何)
438 - The Circumference of the CircleTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=379To calculate the c原创 2013-10-19 22:14:10 · 1532 阅读 · 0 评论