zoukankan      html  css  js  c++  java
  • 洛谷P1183 多边形的面积

    深搜灌水 +  皮克定理

     1 #include <bits/stdc++.h> 
     2 #define For(i,j,k) for(int i=j;i<=k;i++)
     3 #define LL long long 
     4 using namespace std ; 
     5 
     6 struct point{
     7     int x,y ; 
     8 }p[111] ; 
     9 int n,tmp[211][411],mp[211][411],a,b,s ; 
    10  
    11 inline LL read() 
    12 {
    13     LL x = 0 , f = 1 ; 
    14     char ch = getchar() ; 
    15     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; } 
    16     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; } 
    17     return x * f ;  
    18 }
    19 
    20 inline void dfs(int x,int y) 
    21 {
    22     if(mp[x][y]) return ; 
    23     mp[x][y] = 1 ,b++ ; 
    24     dfs(x+1,y) ; dfs(x,y+1) ; 
    25     dfs(x-1,y) ; dfs(x,y-1) ; 
    26 }
    27 
    28 int main() 
    29 {
    30     n = read() ; 
    31     For(i,1,n) {
    32         p[ i ].x = read() ; 
    33         p[ i ].y = read() ; 
    34     }
    35     p[n+1] = p[1] ; 
    36     For(i,1,n) {
    37         if(p[i].x==p[i+1].x) {
    38             a+=abs(p[i+1].y-p[i].y) ; 
    39             For(j,min(p[i].y,p[i+1].y),max(p[i].y,p[i+1].y)) 
    40                 mp[p[i].x][j] = 1 ; 
    41         }
    42         else{
    43             a+=abs(p[i+1].x-p[i].x) ; 
    44             For(j,min(p[i].x,p[i+1].x),max(p[i].x,p[i+1].x)) 
    45                 mp[j][p[i].y] = 1 ; 
    46         }
    47     } 
    48     dfs( p[1].x+1,p[1].y+1 ) ; 
    49     printf("%d
    ",a/2+b-1) ; 
    50     return 0 ; 
    51 }
  • 相关阅读:
    总结几个面试题
    产生下一个排列数的算法
    所谓码农
    简记微软实习生面试
    二维数组作为函数的参数传递
    详细解说 STL 排序(Sort)
    copy()之绝版应用
    STL标准模板库(简介)
    访问控制和继承方式
    常用软件开发模型比较分析
  • 原文地址:https://www.cnblogs.com/third2333/p/7387870.html
Copyright © 2011-2022 走看看