poj2954 Triangle
地址:http://poj.org/problem?id=2954
题目:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6006 | Accepted: 2576 |
Description
A lattice point is an ordered pair (x, y) 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 x1, y1, x2, y2, x3, and y3, where (x1, y1), (x2, y2), and (x3, y3) are the coordinates of vertices of the triangle. All triangles in the input will be non-degenerate (will have positive area), and −15000 ≤ x1, y1, x2, y2, x3, y3 ≤ 15000. The end-of-file is marked by a test case with x1 = y1 = x2 = y2 = x3= y3 = 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
#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的更多相关文章
- 【kuangbin专题】计算几何基础
1.poj2318 TOYS 传送:http://poj.org/problem?id=2318 题意:有m个点落在n+1个区域内.问落在每个区域的个数. 分析:二分查找落在哪个区域内.叉积判断点与线 ...
- poj分类解题报告索引
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [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, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
随机推荐
- Python 中文乱码
1.首行添加 # -*- coding:gb2312 -*- # -*- coding:utf-8 -*- 2.PyCharm设置 在File->setting->File Encodin ...
- chmod 777 修改权限
http://william71.blogbus.com/logs/33484772.html 在Unix和Linux的各种操作系统下,每个文件(文件夹也被看作是文件)都按读.写.运行设定权限.例如我 ...
- 使用MAT分析Java内存
Overview MAT(Memory Analyzer Tool) 是一个JAVA Heaper分析器,可以用来分析内存泄露和减少内存消耗.分析Process showmap中的/dev/ashme ...
- Splay模板 1.0
struct Splay{ int rt,sz; ///根节点,树节点总数 ],fa[N];///值,左右儿子,父亲 void spin(int t){ ///旋转操作 ]==t; son[x][y] ...
- 关于PreparedStatement.addBatch()方法 (转)
Statement和PreparedStatement的区别就不多废话了,直接说PreparedStatement最重要的addbatch()结构的使用. 1.建立链接,(打电话拨号 ) Connec ...
- 【BZOJ3362-3365】USACO水题四连A
[BZOJ3362][Usaco2004 Feb]Navigation Nightmare 导航噩梦 Description 农夫约翰有N(2≤N≤40000)个农场,标号1到N,M(2≤M≤ ...
- angularJS的过滤器!
angularJS过滤器: filter currency date filter json limitTo lowercase number orderBy uppercase ...... Fil ...
- 170614、MySQL存储引擎-MyISAM与InnoDB区别
MyISAM 和InnoDB 讲解 InnoDB和MyISAM是许多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,视具体应用而定.基本的差别为:MyISAM类型不支持事务处理等高级处理 ...
- Sublime 取消每次自动更新弹窗设置
首选项 --> 设置-用户(英文版 : "Preferences - -> "Settings - user"") update_check ...
- pta 习题集5-17 哥尼斯堡的“七桥问题”
哥尼斯堡是位于普累格河上的一座城市,它包含两个岛屿及连接它们的七座桥,如下图所示. 可否走过这样的七座桥,而且每桥只走过一次?瑞士数学家欧拉(Leonhard Euler,1707-1783)最终解决 ...