zoukankan      html  css  js  c++  java
  • POJ1151 Atlantis 水题 计算几何

    http://poj.org/problem?id=1151

    想学一下扫描线线段树,结果写了道水题。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<set>
     7 using namespace std;
     8 const int maxn=110;
     9 int n;
    10 double a1[maxn][4];
    11 int a[maxn][4];
    12 double b[maxn*4],c[maxn*2];
    13 int tot=0,tot1=0;
    14 int main(){
    15     for(int T=1;;T++){
    16         scanf("%d",&n);
    17         if(n==0)break;
    18         tot=0,tot1=0;
    19         for(int i=1;i<=n;i++){
    20             scanf("%lf%lf%lf%lf",&a1[i][0],&a1[i][1],&a1[i][2],&a1[i][3]);
    21             b[++tot]=a1[i][0];b[++tot]=a1[i][2];
    22             c[++tot1]=a1[i][1];c[++tot1]=a1[i][3];
    23         }
    24         sort(b+1,b+1+tot);sort(c+1,c+1+tot1);
    25         tot=unique(b+1,b+1+tot)-b-1;
    26         tot1=unique(c+1,c+1+tot1)-c-1;
    27         for(int i=1;i<=n;i++){
    28             a[i][0]=lower_bound(b+1,b+1+tot,a1[i][0])-b;
    29             a[i][1]=lower_bound(c+1,c+1+tot1,a1[i][1])-c;
    30             a[i][2]=lower_bound(b+1,b+1+tot,a1[i][2])-b;
    31             a[i][3]=lower_bound(c+1,c+1+tot1,a1[i][3])-c;
    32         }double ans=0;
    33         for(int i=1;i<tot;i++){
    34             for(int j=1;j<tot1;j++){
    35                 int f=0;
    36                 for(int z=1;z<=n;z++){
    37                     if(i+1<=a[z][2]&&i>=a[z][0]&&j+1<=a[z][3]&&j>=a[z][1]){
    38                         f=1;break;
    39                     }
    40                 }
    41                 if(f){
    42                     ans+=(b[i+1]-b[i])*(c[j+1]-c[j]);
    43                 }
    44             }
    45         }
    46         printf("Test case #%d
    ",T);
    47         printf("Total explored area: %.2f
    
    ",ans);
    48     }
    49     return 0;
    50 }
    View Code

  • 相关阅读:
    主席树学习记录
    P1072 Hanson 的趣味题 题解
    好文章收集
    计算几何专题
    小问题
    CSP-S2020题解
    上下界网络流
    想到的无法解决的点子
    省选联考2020组合数问题
    省选数学复习
  • 原文地址:https://www.cnblogs.com/137shoebills/p/8695616.html
Copyright © 2011-2022 走看看