pku 2954 Triangle && pku 1265 Area Pick定理的应用 + 叉积求多边形面积
2012-05-21 20:31
597 查看
Pick定理证明:http://translate.google.com/translate?u=http://episte.math.ntu.edu.tw/articles/sm/sm_25_10_1/page4.html&hl=zh-CN&ie=UTF8&sl=zh-TW&tl=zh-CN
http://poj.org/problem?id=2954
这个题意就是求网格内给定三角形三点,然后求他的内部点的个数; pick :s = in + on/2 -1 in内部点数 on外部边上的点数 s 多边形面积这里要求的是in,通常是先求出多边形面积,以及on的值,然后求in。这里on的值得求法是 求整数点(x1,y1),(x2,y2)之间的整数个数 = gcd(|x1-x2|,|y1-y2|);
面积的求法:任意多边形面积(凸多边形+凹凸变形,不包括有两边交叉的多边形)=叉积之和的一半
http://poj.org/problem?id=1265
同上题,只不过这里给定的直接就是dx,dy了。其默认的起点是(0,0)终止的节点也是(0,0)。
http://poj.org/problem?id=2954
这个题意就是求网格内给定三角形三点,然后求他的内部点的个数; pick :s = in + on/2 -1 in内部点数 on外部边上的点数 s 多边形面积这里要求的是in,通常是先求出多边形面积,以及on的值,然后求in。这里on的值得求法是 求整数点(x1,y1),(x2,y2)之间的整数个数 = gcd(|x1-x2|,|y1-y2|);
面积的求法:任意多边形面积(凸多边形+凹凸变形,不包括有两边交叉的多边形)=叉积之和的一半
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #define maxn 4 using namespace std; struct node { int x,y; }p[maxn]; int m,in,on; double s; int gcd(int x,int y) { while (y != 0) { int temp = y; y = x%y; x = temp; } return x; } int main() { int i; while (~scanf("%d%d%d%d%d%d",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y)) { if (!p[0].x && !p[0].y && !p[1].x && !p[1].y && !p[2].x && !p[2].y) break; in = on = s = 0; for (i = 0; i < 3; ++i) { on += gcd(abs(p[(i + 1)%3].x - p[i].x),abs(p[(i + 1)%3].y- p[i].y));//任意两点之间的dx,dy s += p[(i + 1)%3].y*p[i].x - p[i].y*p[(i + 1)%3].x;//任意两点的叉积 } s = s*0.5; if (s < 0) s = -s;//叉积求出来的可能为负,注意处理 in = s + 1 - on/2.0; printf("%d\n",in); } return 0; }
http://poj.org/problem?id=1265
同上题,只不过这里给定的直接就是dx,dy了。其默认的起点是(0,0)终止的节点也是(0,0)。
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #define maxn 107 using namespace std; struct node { int x,y; }p[maxn]; int m,in,on; double s; int gcd(int x,int y) { while (y != 0) { int temp = y; y = x%y; x = temp; } return x; } int main() { int t,i; int dx,dy; int cas = 1; scanf("%d",&t); while (t--) { scanf("%d",&m); p[0].x = p[0].y = 0; s = in = on = 0; for (i = 1; i <= m; ++i) { scanf("%d%d",&dx,&dy); on += gcd(abs(dx),abs(dy)); p[i].x = p[i - 1].x + dx; p[i].y = p[i - 1].y + dy; s += p[i].y*p[i - 1].x - p[i - 1].y*p[i].x; } s = s*0.5; if (s < 0) s = -s; in = s + 1 - on/2.0; printf("Scenario #%d:\n",cas++); printf("%d %d %.1lf\n\n",in,on,s); } return 0; }
相关文章推荐
- POJ 1265 Area pick定理 + 多边形面积求法
- poj 1265 Area【计算几何:叉积计算多边形面积+pick定理计算多边形内点数+计算多边形边上点数】
- POJ 1265-Area(多边形面积、边点、内点-pick定理、叉积)
- pku1265 pick定理 多边形面积
- pku 1654 Area 叉积求多边形面积
- poj2954 && poj1265 Pick定理求面积
- poj1265 & poj2954(皮克定理pick)在格点上的多边形求面积公式
- Area - POJ 1265(pick定理求格点数+求多边形面积)
- POJ 1265 Area (Pick定理&多边形面积)
- POJ1265——Area(Pick定理+多边形面积)
- pku 2954(pick定理的应用)
- pku 1048 Fishnet 叉积求交点 + 叉积求多边形面积
- 向量叉积的应用(三角形面积,线段相交,多边形面积,多边形凹凸性)
- 向量叉积的应用(三角形面积,线段相交,多边形面积,多边形凹凸性)
- 计算几何【1】叉积的应用,判断点在不在某个多边形内+点阵内图形面积(只有公式)
- poj1265--Area(求多边形面积+匹克定理)
- poj1265&&2954 [皮克定理 格点多边形]【学习笔记】
- 格点多边形面积公式(Pick定理)的一个形象解释(转)
- poj 1265 Area (Pick定理+求面积)
- poj 1654:Area 区域 ---- 叉积(求多边形面积)