UVa 10088 - Trees on My Island
来源:互联网 发布:上海 夜总会 知乎 编辑:程序博客网 时间:2024/05/21 02:52
题目:在整数构成的二维平面上,统计多边形内整数坐标点的个数。
分析:计算几何、pick定理。根据pick定理,我们有在坐标为整数的二维平面内,有s=a+b/2-1,其中b是落在边上的点数,a是内部点数。由此可知:a=s-b/2+1,其中s可利用叉乘求解;b利用gcd求解即可。
注意:面积要取绝对值。
#include <iostream>#include <cstdlib>#include <cstdio>using namespace std;typedef long long LL;typedef struct pnode{LL x,y;}point;point P[1005];LL ab( LL v ){if ( v >= 0LL ) return v;else return 0LL-v;}LL gcd( LL a, LL b ){if ( b == 0LL ) return a;return a%b?gcd(b,a%b):b;}LL crossproduct( point a, point b, point c ){return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y)+0LL;}int main(){int N;while ( cin >> N && N ) {for ( int i = 0 ; i < N ; ++ i )cin >> P[i].x >> P[i].y;P[N] = P[0];LL a,b,r,count = 0LL;for ( int i = 0 ; i < N ; ++ i ) {a = ab( P[i+1].x - P[i].x );b = ab( P[i+1].y - P[i].y );r = gcd( a, b );count += r + 0LL;}LL area = 0LL;for ( int i = 2 ; i < N ; ++ i )area += crossproduct( P[0], P[i-1], P[i] );cout << ab(area)/2LL+1LL-count/2LL << endl;}return 0;}
- UVA 10088 Trees on My Island
- UVa 10088 - Trees on My Island
- UVa Problem 10088 Trees on My Island (岛上的树)
- UVA 10088 Trees on My Island(求整顶点多边形内部整点数)
- LightOj 1418 Trees on My Island (Pick定理)
- LightOJ 1418 - Trees on My Island (Pick`s theorem)
- 1418 - Trees on My Island ( Peake's theorem )
- lightoj1418Trees on My Island【pick公式】
- Trees on the level UVA
- UVa Problem 122 - Trees on the level
- UVA 122 - Trees on the level
- uva 122 - Trees on the level
- uva 122 Trees on the level
- UVA-122-Trees on the level
- UVA - 122 Trees on the level
- UVa 122 - Trees on the level
- UVa 122 - Trees on the level
- Uva 122 Trees on the level
- VS2010破解版
- 小项目集锦博客目录(不断更新,总结)
- C#小游戏记忆围棋源码_修正白棋bug版
- Ogrekit 安装
- 分布式事务及其在OFBiz的实现
- UVa 10088 - Trees on My Island
- 使用添加删除windows的系统服务的例子
- mysql忘记root密码怎么办?重设Mysql密码的方法
- IntelliJ IDEA 优化总结
- jQuery可见性过滤选择器
- JAVA的静态变量、静态方法、静态类
- ERROR 1045 (28000): Access denied for user'root'@'localhost'(using password:YES)最近解决方法在!
- memcmp源码
- get post 乱码处理 包装类