随笔分类 -  计算几何

摘要:先对a排序,a相等的话就对b排序;维护一个栈,每次取栈的头两个,和当前的直线相比较;如果当前的直线把头第一个屏蔽,就将他出栈,一直到不能屏蔽为止;代码:#include#include#include#define maxn 500005using namespace std;int st[maxn],top;int num[maxn];struct line{ int a,b; int id; bool operatort.b; else return a1) { if(check(i,st[top-1],st[top-2]... 阅读全文
posted @ 2013-12-04 18:50 Yours1103 阅读(178) 评论(0) 推荐(0)
摘要:题目给我们四个点,要求我们以这四个点为圆心,形成四个相切的圆;求他们的半径和;首先我们从他们中间选出三个点,以这三个点为圆心的三个圆最大可以两两互相相切;证明:假设这三个圆的半径分别为a,b,c,那么形成的三条边分别长为:a+b,a+c,b+c,他们两两之和大于第三边;然后从第四个点出发的圆必定和前面三个的一个或多个相切;所以这个问题就转化成为三对边和的比较;代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 double dis(double x1,double y1,double x2,double y2) 6 { 7 阅读全文
posted @ 2013-11-11 19:45 Yours1103 阅读(121) 评论(0) 推荐(0)
摘要:半平面交,二分;注意,题目的点是顺时针给出的; 1 #include 2 #include 3 #include 4 #define maxn 50010 5 #define eps 1e-6 6 using namespace std; 7 8 int dcmp(double x) 9 { 10 return fabs(x) 0 ? 1 : -1); 11 } 12 13 struct Point 14 { 15 double x; 16 double y; 17 Point(double x = 0, double y = 0):x(... 阅读全文
posted @ 2013-11-05 20:56 Yours1103 阅读(199) 评论(0) 推荐(0)
摘要:半平面交的题;这个题目的亮点就是建模; 1 #include 2 #include 3 #include 4 #define maxn 109 5 #define eps 1e-6 6 using namespace std; 7 8 int dcmp(double x) 9 { 10 return fabs(x) 0 ? 1 : -1); 11 } 12 13 struct Point 14 { 15 double x; 16 double y; 17 Point(double x = 0, double y = 0):x(x), y(... 阅读全文
posted @ 2013-11-05 20:33 Yours1103 阅读(170) 评论(0) 推荐(0)
摘要:半平面的交,二分的方法; 1 #include 2 #include 3 #include 4 #define eps 1e-6 5 using namespace std; 6 7 int dcmp(double x) 8 { 9 return fabs(x) 0 ? 1 : -1); 10 } 11 12 struct Point 13 { 14 double x; 15 double y; 16 Point(double x = 0, double y = 0):x(x), y(y) {} 17 }; 18 typedef Poin... 阅读全文
posted @ 2013-11-05 13:13 Yours1103 阅读(186) 评论(0) 推荐(0)
摘要:旋转卡壳算法;直接在这个上面粘的模板主要用途:用于求凸包的直径、宽度,两个不相交凸包间的最大距离和最小距离···这题就是求凸包的直径 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define eps 1e-9 7 using namespace std; 8 const double pi = acos(-1); 9 10 int dcmp(double x) 11 { 12 return fabs(x) 0 ? 1 : -1); 13 } 14 15 struct Point 1... 阅读全文
posted @ 2013-11-04 20:17 Yours1103 阅读(230) 评论(0) 推荐(0)
摘要:当退化成点和线段的时候,可以不进行特判;因为这种情况已经包括进条件1.2里面了 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define eps 1e-9 7 using namespace std; 8 const double pi = acos(-1); 9 10 int dcmp(double x) 11 { 12 return fabs(x) 0 ? 1 : -1); 13 } 14 15 struct Point 16 { 17 double x; 18 ... 阅读全文
posted @ 2013-11-04 19:50 Yours1103 阅读(215) 评论(0) 推荐(0)
摘要:凸包+一点直线的知识; 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define eps 1e-9 7 using namespace std; 8 const double pi = acos(-1); 9 10 int dcmp(double x) 11 { 12 return fabs(x) 0 ? 1 : -1); 13 } 14 15 struct Point 16 { 17 double x; 18 double y; 19 20 Point(... 阅读全文
posted @ 2013-11-04 16:24 Yours1103 阅读(146) 评论(0) 推荐(0)
摘要:主要是凸包的应用; 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define eps 1e-9 7 using namespace std; 8 const double pi = acos(-1); 9 10 int dcmp(double x) 11 { 12 return fabs(x) 0 ? 1 : -1); 13 } 14 15 struct Point 16 { 17 double x; 18 double y; 19 20 Point(do... 阅读全文
posted @ 2013-11-04 15:34 Yours1103 阅读(132) 评论(0) 推荐(0)
摘要:这个题目的方法是将圆盘分成一个个圆环,然后判断这些圆环是否被上面的圆覆盖;如果这个圆的圆周上的圆弧都被上面的覆盖,暂时把它标记为不可见;然后如果他的头上有个圆,他有个圆弧可见,那么他自己本身可见,并且可以把这条圆弧下面的第一个圆重新标记为可见;另外,圆弧可见还是不可见利用它的中点来进行判断; 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 const int maxn = 100 + 10; 10 const double eps = 1e-1... 阅读全文
posted @ 2013-11-04 15:04 Yours1103 阅读(284) 评论(0) 推荐(0)
摘要:简单的计算几何;可以把0-2*pi分成几千份,然后找出最小的;也可以用三分; 1 #include 2 #include 3 #include 4 #define pi acos(-1) 5 #define eps 1e-6 6 using namespace std; 7 8 struct node 9 {10 double x,y;11 node(double x=0,double y=0):x(x),y(y){ }12 bool operator0)return length(v3);40 else return fabs(cross(v1,v2))/l... 阅读全文
posted @ 2013-11-01 21:01 Yours1103 阅读(137) 评论(0) 推荐(0)
摘要:对于两只狗在经过拐点之前,他们的运动可以简化为一只狗不动,另一只狗以他们的相对速度运动; 1 #include 2 #include 3 #include 4 #define maxn 66 5 #define eps 1e-6 6 using namespace std; 7 8 struct node 9 {10 double x,y;11 node(double x=0,double y=0):x(x),y(y){ }12 };13 node operator-(node u,node v){return node(u.x-v.x,u.y-v.y);}14 node o... 阅读全文
posted @ 2013-10-31 00:36 Yours1103 阅读(266) 评论(0) 推荐(0)
摘要:计算几何边的旋转、直线相交的应用代码: 1 #include 2 #include 3 using namespace std; 4 struct node 5 { 6 double x,y; 7 node(double x=0,double y=0):x(x),y(y){} 8 }a,b,c,d,e,f; 9 node operator-(node u,node v){return node(u.x-v.x,u.y-v.y);}10 node operator+(node u,node v){return node(u.x+v.x,u.y+v.y);}11 node o... 阅读全文
posted @ 2013-10-30 21:09 Yours1103 阅读(169) 评论(0) 推荐(0)
摘要:计算几何;直线交点; 1 #include 2 using namespace std; 3 4 struct node 5 { 6 double x,y; 7 node(double x=0,double y=0):x(x),y(y){ } 8 }a,b,c,d,e,f,p,q,r; 9 node operator-(node u,node v){return node(u.x-v.x,u.y-v.y);}10 node operator+(node u,node v){return node(u.x+v.x,u.y+v.y);}11 node operator*(node... 阅读全文
posted @ 2013-10-30 16:57 Yours1103 阅读(169) 评论(0) 推荐(0)
摘要:湖南大学的oj上有这套比赛;这题是个简单的计算几何,首先去掉重复的边,然后判断是否全部平行;代码: 1 #include 2 #define maxn 105 3 using namespace std; 4 5 struct node 6 { 7 int x1,y1; 8 int x2,y2; 9 } no[maxn];10 11 bool cross(node a,node b)12 {13 int x=(b.x1-a.x1)*(a.y2-a.y1)-(b.y1-a.y1)*(a.x2-a.x1);14 int y=(b.x2-a.x1)*(a.y2-... 阅读全文
posted @ 2013-10-26 19:27 Yours1103 阅读(279) 评论(0) 推荐(0)
摘要:A:大水题;代码: 1 #include 2 #define ll long long 3 using namespace std; 4 5 int main() 6 { 7 ll n,m,a; 8 cin>>n>>m>>a; 9 cout 2 #include 3 #define maxn 1000005 4 using namespace std; 5 int n; 6 char s[50]; 7 void a_to_b() 8 { 9 int a,b;10 int p=maxn-1;11 char t[maxn];12 sscan... 阅读全文
posted @ 2013-10-17 20:52 Yours1103 阅读(154) 评论(0) 推荐(0)
摘要:一个简单的题;感觉像计算几何,其实并用不到什么计算几何的知识;方法:首先对每条边判断一下,看他们能够把平面分成多少份;然后用边来对点划分集合,首先初始化为一个集合;最后如果点的集合等于平面的份数,就说明每块都有一个士兵;代码: 1 #include 2 #include 3 #define maxn 105 4 #define maxm 50005 5 using namespace std; 6 int a[maxn],b[maxn],c[maxn]; 7 long long x[maxm],y[maxm]; 8 int main() 9 {10 int t,n,m;11 s... 阅读全文
posted @ 2013-10-05 15:52 Yours1103 阅读(236) 评论(0) 推荐(0)