随笔分类 -  计算几何

摘要:#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;#define pi acos(-1.0)struct point{ double x; double y;}pp[1010];struct Vector{ double x; double y;};double chaji(Vector a,Vector b)//a*b{ return a.x*b.y-b.x*a.y;} 阅读全文
posted @ 2012-07-28 16:37 willzhang 阅读(145) 评论(0) 推荐(0)
摘要:捣鼓了一整天,随机了100个样例全过还是WA,后来发现最大值设小了。。。T T#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>#include<queue>using namespace std;#define MAX 99999999999999struct point{ double x; double y;};struct line{ point first;//西南 point last; 阅读全文
posted @ 2012-07-28 10:31 willzhang 阅读(180) 评论(0) 推荐(0)
摘要:#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;struct point{ double x; double y;}p[20];struct T{ int xx;// int yy;// int zz;// double mianji;//}res;bool cmp(int a,int b){ return a<b;}point operator-(const p 阅读全文
posted @ 2012-07-24 21:59 willzhang 阅读(143) 评论(0) 推荐(0)
摘要:极角排序#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;struct point{ double x; double y;}a[55];double mu(point a,point b){ return a.x*b.y-b.x*a.y;}bool cmp(const point &a,const point &b){ return mu(a,b)> 阅读全文
posted @ 2012-07-24 20:27 willzhang 阅读(158) 评论(0) 推荐(0)
摘要:纯水题,注意交点不一定是第二个点和第三个点#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;struct Vector{ double x; double y;};struct point{ double x; double y;};Vector operator-(const point a,const point b){ Vector temp; temp.x=a.x 阅读全文
posted @ 2012-07-23 21:24 willzhang 阅读(160) 评论(0) 推荐(0)
摘要://252K 16MS注意隔板不按顺序给出#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;int n,m;double x1,y1,x2,y2;struct point{ double x; double y;};struct T{ point a; point b;//a点在b点上方}line[5500];int res[5500];point temp;bool check(point p,T lin)//判 阅读全文
posted @ 2012-07-16 09:27 willzhang 阅读(111) 评论(0) 推荐(0)
摘要:360K 172MS二分法和叉积代码如下#include<stdio.h>#include<string.h>#include<stdlib.h>int n,m;double x1,y1,x2,y2;struct point{ double x; double y;};struct T{ point a; point b;//a点在b点上方}line[5500];int res[5500];point temp;bool check(point p,T lin)//判断p点在lin的左方返回true,在lin的右方返回false{ double cc=(li 阅读全文
posted @ 2012-07-15 22:05 willzhang 阅读(116) 评论(0) 推荐(0)
摘要:不断添加圆,维护最小圆。如果添加的点i在圆内,不动,否则: 问题转化为求1~I的最小圆:求出1与I的最小圆,并且扫描j=2~(I-1),维护(1)+(i)+(2~j)的最小圆,如果找到J不在最小圆内,问题转化为:求(1~J)+(i)的最小圆。求出I与J的最小圆,继续扫描K=1~(j-1),找到不在最小圆内的,求出I J K三者最小圆,此时找到了(1~j)+(i)的最小圆,可以回到上一步(三点定一圆,所以1~(J-1)一定都在求出的最小圆上)。 这个做法复杂度是O(n)的,当加入圆的顺序随机时,因为三点定一圆,所以不在圆内概率是3/i,求出期望可得是On.以上是百度文库的内容,自己做了些删改以下 阅读全文
posted @ 2012-07-15 11:18 willzhang 阅读(239) 评论(0) 推荐(0)
摘要:这题WA很久,本人还随机了100个样例来测试,结果全过(白浪费我一个小时)然后看了讨论区,就用C++提交了一遍,,于是,,过了,大家记得用C++交一遍输出的时候注意G++对%f和%lf的区别,,,,据说是这样(大神轻拍)#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;#define station 1#define agent 2#define MAX 100010co 阅读全文
posted @ 2012-07-14 17:00 willzhang 阅读(265) 评论(0) 推荐(0)
摘要:第一次做计算几何,看了算法导论的算法,再看了网上的一些代码,发现很多实际上并没有完整地实现分治法,然后试图自己实现失败告终T_T于是有了如下代码,分治法的思想详见算法导论与编程之美耗时是1250ms#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#define MAX 100010struct point{ double x; double y;};double D_MAX=99999999999; point X[MAX];point Y[MAX];dou 阅读全文
posted @ 2012-07-14 11:12 willzhang 阅读(195) 评论(0) 推荐(0)