poj 2954 Triangle(Pick定理)
链接:http://poj.org/problem?id=2954
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5043 | Accepted: 2164 |
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
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
继续用pick定理,area=i + b / 2 -1
注意判结束时不可(a+b+c+d)看是否为零,因为有负数
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm> using namespace std; typedef struct
{
double x,y;
}point; double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
} int gcd(int a,int b)
{
return b ? gcd(b,a%b) : a;
} point p[]; int onEdge(int n)
{
int sum=;
p[n]=p[];
for(int i=; i<n; i++)
{
sum+=gcd(abs((int)(p[i].x-p[i+].x)),abs((int)(p[i].y-p[i+].y)));
}
return sum;
} int main()
{
while(scanf("%lf%lf%lf%lf%lf%lf",&p[].x,&p[].y,&p[].x,&p[].y,&p[].x,&p[].y)!=EOF
&& p[].x!=||p[].y!=||p[].x!=||p[].y!=||p[].x!=||p[].y!=)
{
double area=fabs(crossProduct(p[],p[],p[]))/2.0;
int edge=onEdge();
printf("%d\n",(int)area+-edge/);
}
return ;
}
poj 2954 Triangle(Pick定理)的更多相关文章
- POJ 1265 Area POJ 2954 Triangle Pick定理
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5227 Accepted: 2342 Description ...
- POJ 2954 Triangle (pick 定理)
题目大意:给出三个点的坐标,问在这三个点坐标里面的整数坐标点有多少个(不包含边上的) 匹克定理:I = (A-E) / 2 + 1; A: 表示多边形面积 I : 表示多边形内部的点的个数 E: 表示 ...
- poj 2954 Triangle 三角形内的整点数
poj 2954 Triangle 题意 给出一个三角形的三个点,问三角形内部有多少个整点. 解法 pick's law 一个多边形如果每个顶点都由整点构成,该多边形的面积为\(S\),该多边形边上的 ...
- poj 1265 Area (Pick定理+求面积)
链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- POJ 1265 Area (Pick定理 & 多边形面积)
题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...
- poj 1265 Area(pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4373 Accepted: 1983 Description Bein ...
- [poj 1265]Area[Pick定理][三角剖分]
题意: 给出机器人移动的向量, 计算包围区域的内部整点, 边上整点, 面积. 思路: 面积是用三角剖分, 边上整点与GCD有关, 内部整点套用Pick定理. S = I + E / 2 - 1 I 为 ...
- poj 1265 Area( pick 定理 )
题目:http://poj.org/problem?id=1265 题意:已知机器人行走步数及每一步的坐标 变化量 ,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:1.以 ...
- Area - POJ 1265(pick定理求格点数+求多边形面积)
题目大意:以原点为起点然后每次增加一个x,y的值,求出来最后在多边形边上的点有多少个,内部的点有多少个,多边形的面积是多少. 分析: 1.以格子点为顶点的线段,覆盖的点的个数为GCD(dx,dy),其 ...
随机推荐
- JNI开发流程-JNI/NDK【转】
本文转载自:http://wiki.jikexueyuan.com/project/jni-ndk-developer-guide/workflow.html 开发流程 JNI 全称是 Java Na ...
- 161027、Java 中的 12 大要素及其他因素
对于许多人来说,"原生云"和"应用程序的12要素"是同义词.本文的目的是说有很多的原生云只坚持了最初的12个因素.在大多数情况下,Java 能胜任这一任务.在本 ...
- ubuntu下配置tomcat
配置tomcat 1.解压 tar -zxvf apache-tomcat-7.0.53.tar.gz 2.修改/bin/catalina.sh cygwin=falsedarwin=falseos4 ...
- netstat -aon|findstr 8888 终止进程
netstat -aon|findstr 8888 # 根据端口号查找进程C:\Users\Administrator>netstat -ano | findstr TCP LISTENING ...
- JavaScript 网址
1. javascript 模板引擎 http://aui.github.io/artTemplate/
- hdu5514Frogs(2015ACM-ICPC沈阳赛区F题)
这题很容易转化到一个容斥计数问题.而用指数复杂度的枚举计数法显然会挂,只能考虑别的方法. 首先将a[i]用gcd(a[i], m)替换,排序去重后得到一组m的约数,而m不超过1e9,因此m的所有约数最 ...
- 欧拉回路-Door Man 分类: 图论 POJ 2015-08-06 10:07 4人阅读 评论(0) 收藏
Door Man Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2476 Accepted: 1001 Description ...
- 给用户添加sudo权限
centos中默认创建的新用户是没有sudo权限的. 在文件/etc/sudoers中添加即可: ## Allow root to run any commands anywhere root ALL ...
- linux 文件操作命令
目录操作命令 命令格式 命令 [-选项] [-参数] ls -la /etc 有多个选项时可以合并 ls命令: -a (all) 显示所有文件,包括隐藏文件,那是用.开头的文件 为什么要隐藏(这是个系 ...
- HDU 4630 No Pain No Game 线段树 和 hdu3333有共同点
No Pain No Game Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...