链接:http://poj.org/problem?id=2954

Triangle
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5043   Accepted: 2164

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 = 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

  1. 0 0 1 0 0 1
  2. 0 0 5 0 0 5
  3. 0 0 0 0 0 0

Sample Output

  1. 0
  2. 6

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

继续用pick定理,area=i + b / 2 -1

注意判结束时不可(a+b+c+d)看是否为零,因为有负数

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <iostream>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. typedef struct
  11. {
  12. double x,y;
  13. }point;
  14.  
  15. double crossProduct(point a,point b,point c)
  16. {
  17. return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
  18. }
  19.  
  20. int gcd(int a,int b)
  21. {
  22. return b ? gcd(b,a%b) : a;
  23. }
  24.  
  25. point p[];
  26.  
  27. int onEdge(int n)
  28. {
  29. int sum=;
  30. p[n]=p[];
  31. for(int i=; i<n; i++)
  32. {
  33. sum+=gcd(abs((int)(p[i].x-p[i+].x)),abs((int)(p[i].y-p[i+].y)));
  34. }
  35. return sum;
  36. }
  37.  
  38. int main()
  39. {
  40. while(scanf("%lf%lf%lf%lf%lf%lf",&p[].x,&p[].y,&p[].x,&p[].y,&p[].x,&p[].y)!=EOF
  41. && p[].x!=||p[].y!=||p[].x!=||p[].y!=||p[].x!=||p[].y!=)
  42. {
  43. double area=fabs(crossProduct(p[],p[],p[]))/2.0;
  44. int edge=onEdge();
  45. printf("%d\n",(int)area+-edge/);
  46. }
  47. return ;
  48. }

poj 2954 Triangle(Pick定理)的更多相关文章

  1. POJ 1265 Area POJ 2954 Triangle Pick定理

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5227   Accepted: 2342 Description ...

  2. POJ 2954 Triangle (pick 定理)

    题目大意:给出三个点的坐标,问在这三个点坐标里面的整数坐标点有多少个(不包含边上的) 匹克定理:I = (A-E) / 2 + 1; A: 表示多边形面积 I : 表示多边形内部的点的个数 E: 表示 ...

  3. poj 2954 Triangle 三角形内的整点数

    poj 2954 Triangle 题意 给出一个三角形的三个点,问三角形内部有多少个整点. 解法 pick's law 一个多边形如果每个顶点都由整点构成,该多边形的面积为\(S\),该多边形边上的 ...

  4. poj 1265 Area (Pick定理+求面积)

    链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  5. POJ 1265 Area (Pick定理 & 多边形面积)

    题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...

  6. poj 1265 Area(pick定理)

    Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4373 Accepted: 1983 Description Bein ...

  7. [poj 1265]Area[Pick定理][三角剖分]

    题意: 给出机器人移动的向量, 计算包围区域的内部整点, 边上整点, 面积. 思路: 面积是用三角剖分, 边上整点与GCD有关, 内部整点套用Pick定理. S = I + E / 2 - 1 I 为 ...

  8. poj 1265 Area( pick 定理 )

    题目:http://poj.org/problem?id=1265 题意:已知机器人行走步数及每一步的坐标   变化量 ,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:1.以 ...

  9. Area - POJ 1265(pick定理求格点数+求多边形面积)

    题目大意:以原点为起点然后每次增加一个x,y的值,求出来最后在多边形边上的点有多少个,内部的点有多少个,多边形的面积是多少. 分析: 1.以格子点为顶点的线段,覆盖的点的个数为GCD(dx,dy),其 ...

随机推荐

  1. apache部署django记录

    在ubuntu下通过apache部署django 首先需要下载python,django,apache以及wsgi模块 python基本已经自带,我用的是2.7,不是的话可以重新装一个 下载djang ...

  2. [转]Jexus的常用操作和基本配置

    转自http://www.cnblogs.com/xiaodiejinghong/archive/2013/04/05/3000404.html 3.Jexus的操作 经过两个章节关于Jexus的介绍 ...

  3. vim查找/替换字符串

    1.:s 命令来替换字符串. :s/vivian/sky/ 替换当前行第一个 vivian 为 sky :s/vivian/sky/g 替换当前行所有 vivian 为 sky :n,$s/vivia ...

  4. 利用OpenStack Rest API 创建镜像

    服务端点: image API: POST     /v2/images Request1:     Method:Post     Url: http://192.168.31.147:9292/v ...

  5. JavaEE基础(八)

    1.面向对象(代码块的概述和分类)(了解)(面试的时候会问,开发不用或者很少用) A:代码块概述 在Java中,使用{}括起来的代码被称为代码块. B:代码块分类 根据其位置和声明的不同,可以分为局部 ...

  6. jquery easyui常见问题:

    1.jquery easyui1.4.2 demo在ie10 上加载json的时候没有效果 从官网上下载了jquery easyui1.4.2 里面有个demo文件夹,但是发现底下的demo在IE.3 ...

  7. Asp.net Vnext Filters

    ASP.NET MVC 提供Filters(筛选器)之前或之后调用操作方法执行筛选逻辑,和AOP面向切面编程一样. 本文已经同步到<Asp.net Vnext 系列教程 >中] 本章主要介 ...

  8. [原创]南水之源A*(A-Star)算法

    开发导航之前我看了一些A*(A-Star)算法的例子和讲解.没有求得甚解!不过也从A*(A-Star)算法中得到启发,写了一套自己的A*(A-Star)算法.当然,这不是真正(我也不知道)的A*(A- ...

  9. 20150820 PROCEDURE 模板

    USE [DB_H_F1]GO/****** Object:  StoredProcedure [dbo].[sp_sys_user_add]    Script Date: 08/19/2015 1 ...

  10. poj1811 Prime Test

    http://poj.org/problem?id=1811 #include <cstdio> #include <cstring> #include <algorit ...