zoukankan      html  css  js  c++  java
  • POJ 1265 (pick定理 + 多边形面积)

    题目:传送门

    题意:一个点最初在(0, 0),给你它的运动轨迹,保证是一个多边形,问你这个多边形边界上的格点个数以及多边形内部的格点个数和多边形的面积。

     

    思路: pick定理:一个计算点阵中顶点在格点上的多边形面积公式:S=a+b÷2-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积。

     

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <vector>
    #include <set>
    #include <string>
    #include <math.h>
    #define LL long long
    #define mem(i, j) memset(i, j, sizeof(i))
    #define rep(i, j, k) for(int i = j; i <= k; i++)
    #define dep(i, j, k) for(int i = k; i >= j; i--)
    #define pb push_back
    #define make make_pair
    #define INF INT_MAX
    #define inf LLONG_MAX
    #define PI acos(-1)
    #define fir first
    #define sec second
    using namespace std;
    
    const int N = 1e6 + 5;
    
    int a[N];
    
    int Cas = 0, n;
    int x = 0, y = 0, addx, addy, nx, ny;
    int Point_in, Point_on = 0;
    double s = 0;
    void solve() {
        scanf("%d", &n);
        s = 0; x = 0; y = 0; Point_on = 0;
        rep(i, 1, n) {
            scanf("%d %d", &addx, &addy);
            nx = x + addx;
            ny = y + addy;
            Point_on += __gcd(abs(addx), abs(addy));
            s += (x * ny - y * nx);
            x = nx;
            y = ny;
        }
        if(s < 0) s = -s;
        Point_in = (s - Point_on + 2) / 2;
        printf("Scenario #%d:
    %d %d %.1f
    
    ",++Cas,Point_in,Point_on,s/2.0);
    }
    
    int main() {
    
        int _; scanf("%d", &_);
        while(_--) solve();
    
    //    solve();
    
        return 0;
    
    }
    一步一步,永不停息
  • 相关阅读:
    1014. 福尔摩斯的约会
    1009. 说反话
    1002. 写出这个数
    1031. 查验身份证
    1021. 个位数统计
    1006. 换个格式输出整数
    1058. A+B in Hogwarts
    1027. Colors in Mars
    1019. General Palindromic Number
    Windows 新装进阶操作指南
  • 原文地址:https://www.cnblogs.com/Willems/p/12442081.html
Copyright © 2011-2022 走看看