地址: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. 查看网卡流量:nload

    nload命令用于查看网卡流量,用法如下: [root@localhost ~]$ yum install -y epel-release [root@localhost ~]$ yum instal ...

  2. 《C++ Primer Plus》12.6 复习各种(类和动态内存分配的)技术 笔记

    12.6.1 重载<<运算符要重新定义<<运算符,以便将它和cout一起用来显示对象的内容,请定义下面的友元运算符函数:ostream & operator<&l ...

  3. GROW

    经理今天介绍了一下,GROW,就给他放上来了:   有一个辅导的方法 叫做 GROW (G:goal:R:reality:O:option:W:will)这个辅导方法是这样的,客观地给自己或者别人提问 ...

  4. WPS Word查询某些内容的出现次数

    1.CTRL+F 打开查找窗体

  5. php数据访问之查询关键字

    本文根据数据库中的car表做一个汽车查询页面,巩固php查询关键字操作,感兴趣的小伙伴们可以参考一下   本文实例为大家分享了php查询操作的实现代码,供大家参考,具体内容如下 一.一个关键字查询 主 ...

  6. 关于VO、PO的理解——java的(PO,VO,TO,BO,DAO,POJO)解释

    O/R Mapping 是 Object Relational Mapping(对象关系映射)的缩写.通俗点讲,就是将对象与关系数据库绑定,用对象来表示关系数据. 在O/R Mapping的世界里,有 ...

  7. rpm方式安装 gitlab centos7

    一.使用RPM安装 - 推荐 官方推荐的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/ Tips 1 : Centos 7使用el7 ...

  8. 单用户模式进入centos

    修改root密码----------------单用户模式操作 个人原创博客,转载请注明,否则追究法律责任 author: headsen chen date: 2017-9-30 1,开机后,迅速按 ...

  9. Lucene中最简单的索引和搜索示例

    package com.jiaoyiping.lucene; import org.apache.lucene.analysis.standard.StandardAnalyzer; import o ...

  10. shell爬虫简易脚本(线程数可控)

    1.介绍 以机电之家网站为例 经过初步分析,机电之家的数据量较大,并且数据组织规则较为统一,适合以代码方式进行全量爬取. 企业列表URL统一为http://www.jdzj.com/yp_vlist_ ...