地址: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. Python 收集主机信息

    写一个 python 脚本,收集以下信息 ( CentOS 6 ) : IP地址 <ip>    主机名 <hostname>    操作系统版本 <osver>  ...

  2. Python zmail 模块

    zmail 是 python3 用来收发邮件的一个模块,用法参考: https://mp.weixin.qq.com/s?__biz=MzAxMjUyNDQ5OA==&mid=26535559 ...

  3. CSS美化自己的完美网页

    CSS美化自己的完美网页   CSS概述 css样式: css是英文Cascading Style Sheets的缩写,称为层叠样式表,用于对页面进行美化,CSS的可以使页面更加的美观.基本上所有的h ...

  4. Objective-c为什么要有属性

    属性:为什么要有属性 . 首先是因为实例变量的安全性和继承能力,如果我们允许被继承,子类要动这些实例变量,我们需要能够参与进来,如果子类设置了某个值,我们需要检查范围,保证不会破坏父类,保证不会破坏父 ...

  5. Delphi使用ADO连接网络数据库,断网后重连问题

    原始文章: https://blog.csdn.net/blog_jihq/article/details/11737699# 使用TADOConnection对象连接网络数据库(以MySQL为例), ...

  6. BluePrint和ORM

    一.蓝图创建 #引入库文件 from flask import Blueprint,request,jsonify user = Blueprint( "site", __name ...

  7. Sublime Less 自动编译成css

    1.note编译 .下载notejs https://nodejs.org/en/ .首先你要安装lessc.我是用npm包管理器直接安装的,只需要一条命令,如下: npm install less ...

  8. 【BZOJ2329/2209】[HNOI2011]括号修复/[Jsoi2011]括号序列 Splay

    [BZOJ2329/2209][HNOI2011]括号修复/[Jsoi2011]括号序列 题解:我们的Splay每个节点维护如下东西:左边有多少多余的右括号,右边有多少多余的左括号,同时为了反转操作, ...

  9. linux清理n天前的文件命令

    记得有一次面试时问题改问题.现特此记录 find ${DATADIR}/user*.log -type f -mtime +1 -exec rm {} \; DATADIR是自己定义变量 -mtime ...

  10. LoadRunner 11 安装

    下载地址:http://www.ddooo.com/softdown/61971.htm#dltab LoadRunner是一款专业级别的应用负载测试工具,它可以模拟上千万用户对企业应用进行真实的负载 ...