• POJ 1265 Area (计算几何)(Pick定理)


    Area

                                                  

    大意:每次给你一个点的横纵坐标变化值,求有多少点在多边形上,有多少点在多边形内,和多边形的面积。

    思路:Pick定理。

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

     1 #include <map>
     2 #include <stack>
     3 #include <queue>
     4 #include <math.h>
     5 #include <stdio.h>
     6 #include <stdlib.h>
     7 #include <string.h>
     8 #include <iostream>
     9 #include <limits.h>
    10 #include <algorithm>
    11 #define LL long long
    12 #define max(a,b) ((a)>(b)?(a):(b))
    13 #define min(a,b) ((a)<(b)?(a):(b))
    14 #define max3(a, b, c) (a>b?max(a, c):max(b, c))
    15 #define min3(a, b, c) (a<b?min(a, c):min(b, c))
    16 #define max4(a, b, c, d) max(max(a, b), max(c, d))
    17 #define min4(a, b, c, d) min(min(a, b), min(c, d))
    18 #define eps 1e-9
    19 #define INF 1 << 30
    20 using namespace std;
    21 
    22 int T, n;
    23 int cnt, Ans, a, b;
    24 
    25 struct Point
    26 {
    27     int x, y;
    28 } N[105];
    29 
    30 int Area(Point a, Point b)
    31 {
    32     return a.x*b.y-a.y*b.x;
    33 }
    34 
    35 int gcd(int a, int b)
    36 {
    37     if(b == 0)
    38     {
    39         return a;
    40     }
    41     else
    42     {
    43         return gcd(b, a%b);
    44     }
    45 }
    46 
    47 void Solve()
    48 {
    49     int T;
    50     scanf("%d", &T);
    51     for(int p = 1; p <= T; ++p)
    52     {
    53         scanf("%d", &n);
    54         Ans = cnt = N[0].x = N[0].y = 0;
    55         for(int i = 1; i <= n; ++i)
    56         {
    57             scanf("%d%d", &a, &b);
    58             N[i].x = N[i-1].x+a;
    59             N[i].y = N[i-1].y+b;
    60             Ans += Area(N[i], N[i-1]);
    61             cnt += gcd(abs(a), abs(b));
    62         }
    63         Ans = abs(Ans);
    64         printf("Scenario #%d:
    ", p);
    65         printf("%d %d %.1lf
    
    ", (Ans-cnt+2)/2, cnt, Ans*0.5);
    66     }
    67 }
    68 
    69 int main(void)
    70 {
    71     freopen("data.in", "r", stdin);
    72     //freopen("data.out", "w", stdout);
    73     Solve();
    74 
    75     return 0;
    76 }
    Area
  • 相关阅读:
    Android UI开发 popupwindow介绍以及代码实例
    前端之Android入门(5) – MVC模式(下)
    前端之Android入门(4) – MVC模式(中)
    前端之Android入门(3) – MVC模式(上)
    前端之Android入门(2) – 程序目录及UI简介
    前端之Android入门(1) – 环境配置
    android之SQLite数据库应用(二)
    android之SQLite数据库应用(一)
    android 裁剪图片大小 控制图片尺寸
    Android应用盈利广告平台的嵌入方法详解
  • 原文地址:https://www.cnblogs.com/Silence-AC/p/3586386.html
Copyright © 2020-2023  润新知