地址:http://poj.org/problem?id=2954

题目:

Triangle
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6006   Accepted: 2576

Description

lattice point is an ordered pair (xy) where x and y are both integers. Given the coordinates of the vertices of a triangle (which happen to be lattice points), you are to count the number of lattice points which lie completely inside of the triangle (points on the edges or vertices of the triangle do not count).

Input

The input test file will contain multiple test cases. Each input test case consists of six integers x1y1x2y2x3, and y3, where (x1y1), (x2y2), and (x3y3) are the coordinates of vertices of the triangle. All triangles in the input will be non-degenerate (will have positive area), and −15000 ≤ x1y1x2y2x3y3 ≤ 15000. The end-of-file is marked by a test case with x1 =  y1 = x2 = y2 = x3y3 = 0 and should not be processed.

Output

For each input case, the program should print the number of internal lattice points on a single line.

Sample Input

0 0 1 0 0 1
0 0 5 0 0 5
0 0 0 0 0 0

Sample Output

0
6

Source

 
思路:
  pick定理:对于格点多边形(所有的顶点均在格点上的多边形),其面积公式 2*S = 2*a + b - 2 (其中b为在边上的格点数,a为在多边形内部的格点数)
  端点在格点上的线段穿过的格点数:gcd(abs(pe.x-ps.x),abs(pe.y-ps.y))+1
  也就是说在线段ps,pe上,除了起点ps外经过的格点数。
 #include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int x[],y[]; int main(void)
{
while()
{
int ff=;
for(int i=;i<;i++)
scanf("%d%d",x+i,y+i),ff+=!y[i]&&!x[i];
if(ff==)break;
int cnt=,s=(x[]-x[])*(y[]-y[])-(x[]-x[])*(y[]-y[]);
for(int i=;i<;i++)
cnt+=__gcd(abs(x[(i+)%]-x[i]),abs(y[(i+)%]-y[i]));
printf("%d\n",(abs(s)+-cnt)/);
}
return ;
}

poj2954 Triangle的更多相关文章

  1. 【kuangbin专题】计算几何基础

    1.poj2318 TOYS 传送:http://poj.org/problem?id=2318 题意:有m个点落在n+1个区域内.问落在每个区域的个数. 分析:二分查找落在哪个区域内.叉积判断点与线 ...

  2. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

  3. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  4. [LeetCode] Pascal's Triangle II 杨辉三角之二

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  5. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  6. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  7. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  8. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  9. Triangle - Delaunay Triangulator

    Triangle - Delaunay Triangulator  eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...

随机推荐

  1. Android权限全记录(转)

    常用权限: 读写存储卡装载和卸载文件系统 android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_EXTERNAL_STOR ...

  2. Spring装配Bean的过程补充

    对上一篇的<Spring装配Bean的过程>的过程说一下,不然真产生了误区. 误区在哪里呢?那就是spring bean的作用域问题. 说哈常用的两种作用域:默认是scope = sing ...

  3. 【渗透测试学习平台】 web for pentester -5.代码执行

    Example 1 http://192.168.106.154/codeexec/example1.php?name=".system('uname -a');// Example 2 h ...

  4. docker rmi 详解

    docker rmi 用于删除指定的镜像,常见用法如下: [root@localhost ~]$ docker rmi centos # 根据 REPOSITORY 来删除镜像 [root@local ...

  5. php学习五:数组操作

    前言:由于之前接触过js,所以在学习php的时候,里面继承了js的许多方法,所以数组里面的许多操作和js很相似,但是却比js里面多的多,个人感觉php是集成数组方法最多的一个 ,今天学习的有二十余个, ...

  6. PyQt4布局管理——绝对定位方式

    PyQt4中的布局管理器 布局管理器是编程中重要的一部分.所谓布局管理器是指我们在窗口中安排部件位置的方法.布局管理器有两种工作方式:绝对定位方式(absolute positioning)和布局类别 ...

  7. 96、facebook Fresco框架库源使用(转载)

    各个属性详情:http://blog.csdn.net/y1scp/article/details/49245535 开源项目链接 facebook Fresco仓库:git clone https: ...

  8. 收集的可以下载css3字体图标的网站

    http://icomoon.io/app/ 可以选择跟简单调整图标打包成css3 字体下载, http://www.flaticon.com/categories/weapons

  9. Lucene构建索引时的一些概念和索引构建的过程

    在搜索文档内容之前要做的事情就是对从各种不同来源(网页,数据库,电子邮件等)的文档进行索引,索引的过程就是对内容进行提取,规范化(通过对内容进行建模来实现),然后存储. 在索引的过程中有几个基本的概念 ...

  10. 【BZOJ2453】维护队列/【BZOJ2120】数颜色 分块

    [BZOJ2453]维护队列 Description 你小时候玩过弹珠吗? 小朋友A有一些弹珠,A喜欢把它们排成队列,从左到右编号为1到N.为了整个队列鲜艳美观,小朋友想知道某一段连续弹珠中,不同颜色 ...