LightOj1418 - Trees on My Island(Pick定理)

题目链接:http://lightoj.com/volume_showproblem.php?problem=1418

题意:给你多边形中的顶点,n个点按顺时针或逆时针方向给出,然后求出多边形内部有多少个整数点;

皮克定理:

  在一个多边形中。用I表示多边形内部的点数,E来表示多边形边上的点数,S表示多边形的面积。

  满足:S = I + E/2 - 1;

E,一条边(x1, y1, x2, y2)上的点数(包括两个顶点)= gcd(abs(x1-x2),abs(y1-y2));

#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include<queue>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
#define mod 1000000007
typedef long long LL;
///////////////////////////////////////////////////////////////////////////////////////////////
/*
HDU2036题意:有一个多边形,含有n个顶点,按逆时针方向依次给出,求对应的多边形的面积;
*/
const int N = 10005;
struct point
{
    LL x, y;

    point(){}
    point(LL x, LL y):x(x), y(y) {}

    friend LL operator ^(point p, point q)
    {
        return p.x*q.y - p.y*q.x;
    };
}p[N];

LL gcd(LL a, LL b)
{
    return b==0?a:gcd(b, a%b);
}
int main()
{
    int n, T, t = 1;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d", &n);
        for(int i=1; i<=n; i++)
            scanf("%lld %lld", &p[i].x, &p[i].y);
        p[0] = p[n];

        LL S = 0, E = 0;
        for(int i=1; i<=n; i++)
        {
            S += p[i]^p[i-1];
            E += gcd(abs(p[i].x-p[i-1].x), abs(p[i].y-p[i-1].y));
        }
        LL I = (abs(S)- E)/2 + 1;

        printf("Case %d: %lld\n", t++, I);
    }
    return 0;
}
/*
IN:
1
9
1 2
2 1
4 1
4 3
6 2
6 4
4 5
1 5
2 3
OUT:
Case 1: 8
*/

时间: 2024-09-29 08:51:30

LightOj1418 - Trees on My Island(Pick定理)的相关文章

LightOJ 1418 Trees on My Island (Pick定理)

题目链接:LightOJ 1418 Problem Description I have bought an island where I want to plant trees in rows and columns. So, the trees will form a rectangular grid and each of them can be thought of having integer coordinates by taking a suitable grid point as

UVa 10088 - Trees on My Island (pick定理)

样例: 输入:123 16 39 28 49 69 98 96 55 84 43 51 3121000 10002000 10004000 20006000 10008000 30008000 80007000 80005000 40004000 50003000 40003000 50001000 300040 01000000 01000000 10000000 100000040 0100 0100 1000 100 输出: 21 25990001 999998000001 9801 分析

poj 1265 Area(Pick定理)

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5666   Accepted: 2533 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

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

链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4969   Accepted: 2231 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionag

poj 1265 Area(pick 定理)

链接:poj 1265 题意:从原点出发.给出一些dx,dy移动增量,终于形成一个多边形, 求多边形内部的格点数目,边上的格点数目 .以及面积. 补充知识: 1.以格子点为顶点的线段.覆盖的点的个数为gcd(|dx|,|dy|).当中,|dx|,|dy|分别为线段横向增量和纵向增量. 2.Pick定理:设平面上以格子点为顶点的多边形的内部点个数为a.边上点个数为b.面积为S,则 S = a + b/2 -1. 3.随意一个多边形的面积等于以多边形边上的某点为固定点.按顺序求其余点相邻两个点与该点

POJ 1265 Area POJ 2954 Triangle Pick定理

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5227   Accepted: 2342 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

pick定理:面积=内部整数点数+边上整数点数/2-1

1 //pick定理:面积=内部整数点数+边上整数点数/2-1 2 // POJ 2954 3 4 #include <iostream> 5 #include <cstdio> 6 #include <cstdlib> 7 #include <algorithm> 8 #include <vector> 9 #include <math.h> 10 using namespace std; 11 #define LL long lo

POJ1265——Area(Pick定理+多边形面积)

Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new research and development facility the company has installed the latest system of surveilla

PICK定理

PICK定理: S=I+O/2-1 S为多边形面积,I多边形内部的格点,O是多边形边上的格点 其中边上格点求法: 假设两个点A(x1,y1),B(x2,y2) 线段AB间格点个数为gcd(abs(x1-x2),abs(y1-y2))-1 特判x1-x2==0 或者 y1-y2==0,则覆盖的点数为 y2-y1 或 x2-x1 POJ 2594 Triangle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5106