zoukankan      html  css  js  c++  java
  • poj1265(Area)

    题目地址:Area

    题目大意:

         给你m个点x,y坐标的变化大小,形成一个封闭的图形,求出在图形上点的数目和在多边形内点的个数(每个点的距离间隔为“1”)和形成区域面积的大小。

    解题思路:

        因为要求在多边形的边上和内部的点,想到pick定理:

    pick定理:
                    设F为平面上以格子点为定点的单纯多边形,则其面积为:S=on/2+in-1。 
    
                    on为多边形边上点格点的个数,in为多边形内部格点的个数。 
    
                    可用其计算多边形的面积,边界格点数或内部格点数。
    

      首先可以通过叉积来求封闭多边形的面积,然后通过坐标变化的最大公约数可以确定移动到下一顶点时途经的顶点个数,最后通过pick定理求其内部的顶点。

    代码:

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <sstream>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <cstdio>
     7 #include <string>
     8 #include <bitset>
     9 #include <vector>
    10 #include <queue>
    11 #include <stack>
    12 #include <cmath>
    13 #include <list>
    14 //#include <map>
    15 #include <set>
    16 using namespace std;
    17 /***************************************/
    18 #define ll long long
    19 #define int64 __int64
    20 /***************************************/
    21 const int INF = 0x7f7f7f7f;
    22 const double eps = 1e-8;
    23 const double PIE=acos(-1.0);
    24 const int d1x[]= {0,-1,0,1};
    25 const int d1y[]= {-1,0,1,0};
    26 const int d2x[]= {0,-1,0,1};
    27 const int d2y[]= {1,0,-1,0};
    28 const int fx[]= {-1,-1,-1,0,0,1,1,1};
    29 const int fy[]= {-1,0,1,-1,1,-1,0,1};
    30 /*vector <int>map[N];map[a].push_back(b);int len=map[v].size();*/
    31 /***************************************/
    32 void openfile()
    33 {
    34     freopen("data.in","rb",stdin);
    35     freopen("data.out","wb",stdout);
    36 }
    37 priority_queue<int> qi1;
    38 priority_queue<int, vector<int>, greater<int> >qi2;
    39 /**********************华丽丽的分割线,以上为模板部分*****************/
    40 
    41 struct node
    42 {
    43     double x,y;
    44 }p[200];
    45 int gcd(int a,int b)
    46 {
    47     return b==0?a:gcd(b,a%b);
    48 }
    49 int EPS(double f)
    50 {
    51     if (fabs(f)<eps)
    52         return 0;
    53     return f>0?1:-1;
    54 }
    55 double cha(node b1,node a1)
    56 {
    57     return a1.x*b1.y-a1.y*b1.x;
    58 }
    59 int main()
    60 {
    61 
    62     int cas,cnt=1;
    63     scanf("%d",&cas);
    64     while(cas--)
    65     {
    66         int n;
    67         memset(p,0,sizeof(p));
    68         scanf("%d",&n);
    69         double xx,yy;
    70         double area=0;
    71         int onp=0;
    72         int i;
    73         for(i=1;i<=n;i++)
    74         {
    75             scanf("%lf%lf",&xx,&yy);
    76             p[i].x=xx+p[i-1].x;
    77             p[i].y=yy+p[i-1].y;
    78             onp+=fabs(gcd(xx,yy));
    79             area+=cha(p[i],p[i-1]);
    80         }
    81         int inp=area/2+1-onp/2;
    82         printf("Scenario #%d:
    %d %d %.1f
    
    ",cnt++,inp,onp,area/2.0);
    83     }
    84     return 0;
    85 }
    View Code
    屌丝终有逆袭日,*******。
  • 相关阅读:
    多线程编程
    Phthon环境搭建
    网站开发语言方案的选择
    NSTimer的一个误区
    一个tableview的自带动画
    一个扇形的动画效果
    一点两个uiview动画切换的体会
    关于gcd一些自己的理解。
    使用到定时器,单例和协议的一个小应用(2 )
    使用到定时器,单例和协议的一个小应用(1)
  • 原文地址:https://www.cnblogs.com/ZhaoPengkinghold/p/3880432.html
Copyright © 2011-2022 走看看