地址: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. laravel 控制器构造方法注入request对象

    IndexController: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\ ...

  2. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)

    使用maven打包的时候出现如下错误: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compil ...

  3. Python3 requests 库

    requests 安装 使用 requests 发送 GET 请求 使用 requests 发送 POST 请求 使用 requests 维持会话 使用 requests 访问 HTTPS 使用 re ...

  4. poj_3580 伸展树

    自己伸展树做的第一个题 poj 3580 supermemo. 题目大意 对一个数组进行维护,包含如下几个操作: ADD x, y, d 在 A[x]--A[y] 中的每个数都增加d REVERSE ...

  5. JS-运动基础——案例应用:淡入淡出效果

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. MyBatis——日志

    Logging Mybatis内置的日志工厂提供日志功能,具体的日志实现有以下几种工具: SLF4J Apache Commons Logging Log4j 2 Log4j JDK logging ...

  7. Android Fingerprint系列之google原生界面

    ENV: Anroid M 6.0 1. 录入指纹引导界面 2.指纹要求先设置密码或验证密码界面(已经添加安全密码) 3.引导用户寻找指纹传感器 4.录入指纹界面 5.指纹录入结束界面

  8. 【Android N 7】使用量统计usagestats

    Android N 7.1.1 高通 1. /data/system/usagestats/0 2. 每天使用量统计 /data/system/usagestats/0/daily 查看数值: cat ...

  9. 【BZOJ4556】[Tjoi2016&Heoi2016]字符串 后缀数组+二分+主席树+RMQ

    [BZOJ4556][Tjoi2016&Heoi2016]字符串 Description 佳媛姐姐过生日的时候,她的小伙伴从某东上买了一个生日礼物.生日礼物放在一个神奇的箱子中.箱子外边写了一 ...

  10. linux shell中FS、OFS、RS、ORS图解

    在linux 中,总是会忘记FS\OFS\RS\ORS的使用 下面一张图非常明晰的显示