Triangle - POJ 2954(求三角形内的格子点的个数)
Pick公式:平面上以格子点为顶点的简单多边形的面积=边上的点数/2+内部的点数+1。
代码如下:
----------------------------------------------------------------------------------------------------------------------------
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std; const int MAXN = ;
const double EPS = 1e-; struct point
{
int x, y;
}p[MAXN]; int GCD(int m, int n)
{
if(!m || !n)
return m+n;
return GCD(n, m%n);
} int main()
{
while()
{
int ok=; for(int i=; i<; i++)
{
scanf("%d%d", &p[i].x, &p[i].y);
if(p[i].x || p[i].y)
ok = ;
} if(!ok)break;
p[] = p[]; int cnt=, area=; for(int i=; i<; i++)
{
cnt += GCD(abs(p[i].x-p[i+].x), abs(p[i].y-p[i+].y));
area += p[i].x*p[i+].y - p[i].y*p[i+].x;
}
if(area < )area = -area; printf("%d\n", (area-cnt)/+);
} return ;
}
Triangle - POJ 2954(求三角形内的格子点的个数)的更多相关文章
- POJ 1265 Area POJ 2954 Triangle Pick定理
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5227 Accepted: 2342 Description ...
- poj 2954 Triangle 三角形内的整点数
poj 2954 Triangle 题意 给出一个三角形的三个点,问三角形内部有多少个整点. 解法 pick's law 一个多边形如果每个顶点都由整点构成,该多边形的面积为\(S\),该多边形边上的 ...
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- poj 1090:The Circumference of the Circle(计算几何,求三角形外心)
The Circumference of the Circle Time Limit: 2 Seconds Memory Limit: 65536 KB To calculate the c ...
- hdu 2105:The Center of Gravity(计算几何,求三角形重心)
The Center of Gravity Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- poj 1265&&poj 2954(Pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5811 Accepted: 2589 Description ...
- TZOJ 2519 Regetni(N个点求三角形面积为整数总数)
描述 Background Hello Earthling. We're from the planet Regetni and need your help to make lots of mone ...
- HDU 2036 叉乘求三角形面积
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- hrbustoj 1142:围困(计算几何基础题,判断点是否在三角形内)
围困 Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 360(138 users) Total Accepted: 157(12 ...
随机推荐
- apache .htaccess 伪静态重定向,防盗链 限制下载...
301全站跳转 RewriteEngine OnRewriteCond %{HTTP_HOST} ^www\.old\.net$ [NC]RewriteRule ^(.*)$ http://www.n ...
- IE11的CSS兼容性问题
最近测试给了我一大堆BUG,一瞅发现全是IE11的.吐槽一下这个浏览器真的比较特立独行.很多默认的样式跟别的浏览器不同,而且最明显的一点应该是padding左右内边距往往比别的浏览器大了一倍.但是当需 ...
- 2016年1月编程语言排行榜:Java荣获2015年度冠军
Java因于2015年人气增幅最大(+ 5.94%),故获得2015年的TIOBE指数的编程语言奖,同时成为15年年度冠军, Visual Basic.NET(+ 1.51%)和Python(+ 1. ...
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
关于网页中第一行<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- 读《CSCW的一种建模与实现方法》
这篇论文为我们描述了作者构建的一种基于交互.活动.协作三层结构的协同工作模型,并提出了一种采用“镜头焦点”和“自由交互”相结合的协作模型实现方法. 计算机支持的协同工作就是利用计算机技术将时间上分离. ...
- Makefile与shell脚本的区别
引用博客:Makefile与shell脚本区别 在Makefile可以调用shell脚本,但是Makefile和shell脚本是不同的.本文试着归纳一下Makefile和shell脚本的不同. 1.s ...
- 怎么利用ultraISO对一个文件夹制作ISO镜像
1. 运行UltraISO软件,选择好需要转换成ISO的文件,直接拖到UltraISO的界面中. 2.点击“另存为”按钮,选择存放路径并写上ISO文件的名称,文件保存类型选择为ISO格式,点击“保存” ...
- Morgan stanley 电话面试
首先是聊项目, 不会涉及到具体的技术问题 1.C和C++的区别:C++里的RTTI 2.vector 和 list的区别 : casting operator ; smart pointer. 3.数 ...
- Android的Handler总结
一.Handler的定义: 主要接受子线程发送的数据, 并用此数据配合主线程更新UI. 解释: 当应用程序启动时,Android首先会开启一个主线程 (也就是U ...
- 【POJ 1741】 Tree (树的点分治)
Tree Description Give a tree with n vertices,each edge has a length(positive integer less than 100 ...