上一页 1 ··· 6 7 8 9 10 11 12 13 下一页
摘要: 计算几何类型的题,判断点是否在多边形内,只是这个多边形变成了任意的多边形,这种情况下,用做射线的方法进行判定,要处理两种特殊情况1.正好交点在某个顶点上,这个在真正的算法语言描述里说是当和交点相连的另外两个点如果在交点的同一侧,则算是两个点,若异侧则算一个点,但是这个实现起来确实比较麻烦,其实这个可以用另外一个想法解决,和一个线段交于一个顶点时,如果交的点是两个点中,y坐标较大(或较小)的,则算是一个交点,这样其实等同于理论里的同侧异侧的解决办法View Code 1 #include<iostream> 2 #include<cstdio> 3 #include< 阅读全文
posted @ 2012-05-05 00:18 zhenhai 阅读(416) 评论(0) 推荐(0)
摘要: 链接:http://poj.org/problem?id=1113求凸包的模板题,只是这个精度卡死人,而且我的g++死活过不了,换成c++就过了,唉,poj上太多这样的题了,实在让人无语啊View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 #define N 1005 5 #define pi 3.141592653 6 struct point 7 { 8 int x,y; 9 };10 int n;11 int dis(point p1,point p2)12 { 阅读全文
posted @ 2012-05-04 21:18 zhenhai 阅读(169) 评论(0) 推荐(0)
摘要: 链接:http://poj.org/problem?id=2318这道题是比较简单的计算几何问题,只要找每个点应该在第几块内部就可以了,用叉积判断方向,二分查找View Code 1 #include<stdio.h> 2 #include<string.h> 3 struct point 4 { 5 double x,y; 6 }; 7 struct 8 point a[10005]; 9 int num[5005];10 double mul(point p1,point p2,point p3)//叉积11 {12 return (p2.x-p1.x)*(p3.. 阅读全文
posted @ 2012-05-04 12:24 zhenhai 阅读(211) 评论(0) 推荐(0)
摘要: 链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1392二分匹配的多重匹配再加上二分枚举,本来以为用km算法呢,但是想了下要找的是边的最大值,看来是不可行。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define N 210 5 #define M 35 6 #define C 20 7 #define inf 0xfffffff 8 us 阅读全文
posted @ 2012-05-03 23:25 zhenhai 阅读(245) 评论(0) 推荐(0)
摘要: 这是这道题的二进制转化的解法,效率明显要高很多View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define N 100005 4 #define M 18 5 int a[N]; 6 int v[N]; 7 int wei[N]; 8 int max(int a,int b) 9 {10 return a>b?a:b;11 }12 int main()13 {14 int n,m,w,c,t,i,j,k,weight,val;15 int x,y;16 scanf("%d",& 阅读全文
posted @ 2012-05-03 21:21 zhenhai 阅读(214) 评论(0) 推荐(0)
摘要: 链接:http://poj.org/problem?id=2195这道题是二分图的最佳匹配问题,而且属于最小匹配,km算法的模版题,题目保证了人数和房子数相等,这是自己第一道km算法题,刚开始对km算法不理解,看各种讲解,终于搞懂了其运行过程和能求出解的原因。km算法保证在整个算法的运行过程中对于匹配x,y保证lx[x]+ly[y]>=w(x,y);最终找到的是lx[x]+ly[y]=w(x,y)的解。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #def 阅读全文
posted @ 2012-05-03 19:20 zhenhai 阅读(253) 评论(0) 推荐(0)
摘要: 链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1390这道题,真的挺厉害,虽然用到的东西都不难,但是考察了很多方面,树状数组和二分,这个全用到了,并且还要记录是否访问过View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define N 100005 4 int a[N]; 5 int used[N]; 6 int n; 7 int lowbit(int x) 8 { 9 return x&am 阅读全文
posted @ 2012-05-02 22:46 zhenhai 阅读(224) 评论(0) 推荐(0)
摘要: 链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1049这道题我是用的康托展开做的,优化了判断变化后的数的过程,这道题算是一道数学题吧,应该要算是组合数学里的View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define N 370000 4 int used[N]; 5 int g[N];//存储数 6 int step[N];//每种状态需要的最小步数,为-1则不可达 7 int fac[1 阅读全文
posted @ 2012-05-02 19:55 zhenhai 阅读(489) 评论(0) 推荐(0)
摘要: 这是一道有依赖的背包的经典题目,考虑到每个物品最多有两个子物品,最多会有四种状态,所以可以转化为01背包进行枚举状态View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define N 3250 4 #define M 65 5 int a[N]; 6 int s[M][4]; 7 int v[M][3]; 8 int max(int a,int b) 9 {10 return a>b?a:b;11 }12 int main()13 {14 int n,m;15 int i,j,k;16 int f;17.. 阅读全文
posted @ 2012-05-01 22:51 zhenhai 阅读(188) 评论(0) 推荐(0)
摘要: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191多重背包题目,转化为01背包求解View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define N 105 4 int a[N]; 5 int wei[N]; 6 int pri[N]; 7 int b[N]; 8 int max(int a,int b) 9 {10 return a>b?a:b;11 }12 int main()13 {14 int t;15 int n,m,i,j,k;16 scanf.. 阅读全文
posted @ 2012-05-01 20:44 zhenhai 阅读(177) 评论(0) 推荐(0)
上一页 1 ··· 6 7 8 9 10 11 12 13 下一页