随笔分类 - 计算几何
摘要:题目大意:给出三个点的坐标,问在这三个点坐标里面的整数坐标点有多少个(不包含边上的)匹克定理:I = (A-E) / 2 + 1;A: 表示多边形面积 I : 表示多边形内部的点的个数 E:表示在多边形上的点的个数 // Time 0ms; Memory 164K#include
#include
#include using namespace std; typedef struct point { int x,y; point(int xx=0,int yy=0):x(xx),y(yy){}
}vector; point a,b,c;
vector u,v,w; vector...
阅读全文
摘要:题目大意:已知机器人行走步数及每一步的坐标变化量,求机器人所走路径围成的多边形的面积、多边形边上和内部的点的数量。思路:叉积求面积,pick定理求点。pick定理:面积=内部点数+边上点数/2-1。// Time 0ms; Memory 236K#include
#include
#include using namespace std; struct point { int x,y; point(int xx=0,int yy=0):x(xx),y(yy){}
}a,b;
int gcd(int x,int y)
{ static int t; for(;t=y;y=x%y,x...
阅读全文
摘要:题意:从原点出发,沿着8个方向走,每次走1个点格或者根号2个点格的距离,最终回到原点,求围住的多边形面积。分析:直接记录所经过的点,然后计算多边形面积。注意,不用先保存所有的点,然后计算面积,边走变算,不然会超内存。最多有1000000个点。注意:精度问题,使用long long /__int64,直接使用double不准确。方向的处理使用数组。// Time 94ms; Memory 1036K
#include
#include
#define maxn 1000010 using namespace std; char s[maxn];
long long dx[]={-1,0,1,..
阅读全文
摘要:题目大意:给你n棵树,可以用这n棵树围一个圈,然后在圈里面可以养牛,每个牛需要50平方米的空间,问最多可以养多少牛?其实就是求一个凸包,计算凸包面积,然后除以50,然后就得到答案,直接上模板了。凸包这一类型的题目差不多,可以作为模板使用,时间复杂度是NlogN。//Time 32ms; Memory 568K#include
#include using namespace std; int n; typedef struct point { double x,y; point(double xx=0,double yy=0):x(xx),y(yy){}
}vector; poi...
阅读全文
摘要:题目大意grandfather给k一块凸包的土地,有钉子钉在凸包的边上,现在其中一些钉子掉掉了,判断K是否能根据剩下的钉子判断出原来这边凸包的土地,能输出YES不能输出NO思路如果根据剩余的点作出的凸包上的每一条边除两边端点意外还有多余的点。那么就是YES,注意: 有可能只有一条边,那么一定是NO;// Time 16ms; Memory 272K#include
#include using namespace std; int n; typedef struct point { double x,y; point(double xx=0,double yy=0):x(xx),...
阅读全文
摘要:题意:是有n棵树,每棵的坐标,价值和长度已知,要砍掉若干根,用他们围住其他树,问损失价值最小的情况下又要长度足够围住其他树,砍掉哪些树。。思路:先求要砍掉的哪些树,在求剩下的树求凸包,在判是否可行。(枚举+凸包)// Time 407ms; Memory 200K#include
#include
#include
#include
#include
#define inf 200000
using namespace std; bool vis[15],tvis[15];
int n,m,minv,tn; typedef struct point
{ double x,y; int ...
阅读全文
摘要:大致题意:就是给出三维坐标系上的一些球的球心坐标和其半径,搭建通路,使得他们能够相互连通。如果两个球有重叠的部分则算为已连通,无需再搭桥。求搭建通路的最小费用(费用就是边权,就是两个球面之间的距离)。#include
#include
using namespace std;
int vis[105],n;
double map[105][105],l;
double dis(double x1,double y1,double z1,double x2,double y2,double z2)
{ return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z.
阅读全文
摘要:#include
#include
using namespace std;
typedef struct point
{ double x,y; point(double x=0.0,double y=0.0):x(x),y(y){}
}vector;
point p[1000010],c;
vector operator - (point a,point b) {return vector(a.x-b.x,a.y-b.y);}
point operator + (point a,point b) {return point(a.x+b.x,a.y+b.y);}
point ...
阅读全文
摘要:#include
int main()
{ int i,n,x[100],y[100]; double s; while(scanf("%d",&n)==1 && n) { s=0.0; for(i=0;i<n;i++) scanf("%d%d",&x[i],&y[i]); for(i=1;i<n-1;i++) { s+=x[0]*(y[i]-y[i+1])+x[i]*(y[i+1]-y[0])+x[i+1]*(y[0]-y[i]); ...
阅读全文
摘要:其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中。之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的算法,在很多领域有着重要的用途(例如本人的专业,GIS)。以后若有机会,我会补充、完善这个列表。计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板很重要,模板必须高度可靠。3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面大部分是模板。如果代码一片混乱,那么会严重影响做题正确率。4.注意精度控制。5.能用整数的地方尽量用整数,要想到扩大数据的方法(扩大一倍,或扩大sqrt2)。因为整数不用
阅读全文
摘要:旋转卡壳求最远点对;#include
#include
using namespace std;
int n,k;
double dt;
typedef struct point
{ double x,y; point(double xx=0,double yy=0):x(xx),y(yy){}
}vector;
point p[50010],q[50010];
struct line
{ vector v;
}li,lj;
void sort1(point *a,int x,int y,point *t)
{ int m,u,v,i; if(y-x>1) { m=x+(y-x...
阅读全文
摘要:#include
#include
#include
#include
using namespace std;
const double eps=1e-6;
typedef struct point3
{ double x,y,z; point3(double x=0,double y=0,double z=0):x(x),y(y),z(z){}
}vector3;
struct face
{ point3 a,b,c,d; vector3 n; face(){} face(point3 a,point3 b,point3 c,point3 d,vector3 n):a(a),b...
阅读全文
摘要://Time 0ms, Memory 568KB#include
#include
#include
using namespace std;
const double pi=2.0*asin(1.0);
int main()
{ double a,b,h,v; int t,i=1; cin>>t; while(t--) { cin>>a>>b>>h; if(h>b) h=b; v=pi*a*b*(h-h*h*h/(3*b*b)+2*b/3); cout<<"Case "<<i++<<
阅读全文
摘要:#include #include #include #include using namespace std; struct Point { double x,y; }; struct Segment { Point p1,p2; }; double cross(const Point& o,const Point & a,const Point& b) { return (a.x - o.x)*(b.y-o.y) - (a.y - o.y)* (b.x - o.x); } ...
阅读全文
摘要:#include
#include
using namespace std;
const double PI=acos(-1.0);
int n,l;
typedef struct point
{ double x,y; point(double xx=0,double yy=0):x(xx),y(yy){}
}vector;
point p[1010],q[1010];
void sort1(point *a,int x,int y,point *t)
{ int m,u,v,i; if(y-x>1) { m=x+(y-x)/2; u=x,v=m,i=x; sort1(...
阅读全文