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(求三角形内的格子点的个数)的更多相关文章

  1. POJ 1265 Area POJ 2954 Triangle Pick定理

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5227   Accepted: 2342 Description ...

  2. poj 2954 Triangle 三角形内的整点数

    poj 2954 Triangle 题意 给出一个三角形的三个点,问三角形内部有多少个整点. 解法 pick's law 一个多边形如果每个顶点都由整点构成,该多边形的面积为\(S\),该多边形边上的 ...

  3. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  4. poj 1090:The Circumference of the Circle(计算几何,求三角形外心)

    The Circumference of the Circle Time Limit: 2 Seconds      Memory Limit: 65536 KB To calculate the c ...

  5. hdu 2105:The Center of Gravity(计算几何,求三角形重心)

    The Center of Gravity Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. poj 1265&&poj 2954(Pick定理)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5811   Accepted: 2589 Description ...

  7. TZOJ 2519 Regetni(N个点求三角形面积为整数总数)

    描述 Background Hello Earthling. We're from the planet Regetni and need your help to make lots of mone ...

  8. HDU 2036 叉乘求三角形面积

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...

  9. hrbustoj 1142:围困(计算几何基础题,判断点是否在三角形内)

    围困 Time Limit: 1000 MS     Memory Limit: 65536 K Total Submit: 360(138 users) Total Accepted: 157(12 ...

随机推荐

  1. PhoneGap与WAP站静态化

    最近在参与的WAP站项目,决定将所有页面都静态化处理,登录验证.价格数据等都通ajax动态的方式实现.开始这么规划的目前是为了页面提高网站加载速度及SEO,最近看到了一篇报道phonegap buil ...

  2. js异步脚本

    1.延迟脚本 HTML4.01为<script>标签定义了defer属性,为了表明脚本在执行时不会影响页面的构造.也就是说,脚本会在整个页面都解析完毕后再运行.因此在<script& ...

  3. 玩转HTML5移动页面(动效篇)

    原文:http://www.grycheng.com/?p=458 作为一名前端,在拿到设计稿时你有两种选择: 1.快速输出静态页面 2.加上高级大气上档次狂拽炫酷屌炸天的动画让页面动起来 作为一个有 ...

  4. lnmp安装--php与nginx结合

    软件环境: linux:centos5. nginx:.tar.gz php:.tar.gz lnmp与lamp的区别? lnmp(linux+nginx+mysql+php)的提法相对于lamp(l ...

  5. python调用Moxa PCOMM Lite通过串口Ymodem协议发送文件

    本文采用python 2.7编写. 经过长期搜寻,终于找到了Moxa PCOMM Lite.调用PCOMM.DLL可以非常方便的通过串口的Xmodem.Ymodem.Zmodem等协议传输文件,而无需 ...

  6. 如何利用C生成.so供Mono调用

    Mono诞生的初衷是为了吸引更多的Windows .Net程序员来加入Linux平台的开发.但在Linux世界中C语言依然是 主流.很多时候一些关键应用(比如大型 笛卡儿 乘积运算.需要调用平台硬件功 ...

  7. 小Z的创业经历 谢谢支持

    写这篇文章的目的是跟大家分享下创业的一些想法,经历.希望对你有所帮助或有所思考.  我想用6篇文章介绍下前期创业经历 1.怎么创业了? 2.万事开头难,怎么开始呢? 3.我们的系统详情(上) 4.我们 ...

  8. SQL server 开启 cmdshell

    GO RECONFIGURE GO GO RECONFIGURE GO EXEC master..xp_cmdshell 'net use Z: \\192.168.11.1\192.168.11.4 ...

  9. VMware配置回环地址用于测试

           我们在开发过程中,很可能需要一台服务器用于测试,在这种环境下,我们很可能需要用到vmware来构建这样的开发环境.但如果当前处在一个离线,或是不在网内的环境下,我们所搭建的环境有可能无法 ...

  10. [topcoder]ActivateGame

    http://community.topcoder.com/stat?c=problem_statement&pm=10750&rd=14153 http://apps.topcode ...