zoukankan      html  css  js  c++  java
  • hdu 1255 覆盖的面积 (Bruceforce)

    Problem - 1255

      暴力统计覆盖超过一次的区域。1y。

    代码如下:

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <iostream>
     5 #include <algorithm>
     6 #include <set>
     7 
     8 using namespace std;
     9 
    10 typedef pair<double, int> PDBI;
    11 multiset<PDBI> pos;
    12 #define MPR make_pair
    13 #define FI first
    14 #define SE second
    15 const int N = 1111;
    16 double rec[N][4];
    17 
    18 struct Mark {
    19     double x1, x2, y;
    20     bool end;
    21     Mark() {}
    22     Mark(double x1, double x2, double y, bool end) :
    23         x1(x1), x2(x2), y(y), end(end) {}
    24     bool operator < (Mark x) const { return y < x.y;}
    25 } mk[N << 1];
    26 
    27 int main() {
    28     int n, T;
    29     cin >> T;
    30     while (T-- &&  cin >> n) {
    31         for (int i = 0; i < n; i++) {
    32             for (int j = 0; j < 4; j++) {
    33                 cin >> rec[i][j];
    34             }
    35             if (rec[i][0] > rec[i][2]) swap(rec[i][0], rec[i][2]);
    36             if (rec[i][1] > rec[i][3]) swap(rec[i][1], rec[i][3]);
    37             mk[i << 1] = Mark(rec[i][0], rec[i][2], rec[i][1], false);
    38             mk[i << 1 | 1] = Mark(rec[i][0], rec[i][2], rec[i][3], true);
    39         }
    40         sort(mk, mk + (n << 1));
    41         pos.clear();
    42         if (mk[0].end) {
    43             puts("WTF?!!");
    44             while (1) {}
    45         }
    46         pos.insert(MPR(mk[0].x1, 1));
    47         pos.insert(MPR(mk[0].x2, -1));
    48         multiset<PDBI>::iterator msi;
    49         double area = 0.0;
    50         for (int i = 1, end = n << 1; i < end; i++) {
    51             msi = pos.begin();
    52             int cnt = 0;
    53             double last, sum = 0.0;
    54             while (msi != pos.end()) {
    55                 double fi = (*msi).FI;
    56                 int se = (*msi).SE;
    57                 if (se > 0) {
    58                     cnt++;
    59                     if (cnt == 2) last = fi;
    60                 } else {
    61                     cnt--;
    62                     if (cnt == 1) sum += fi - last;
    63                 }
    64                 msi++;
    65             }
    66             area += sum * (mk[i].y - mk[i - 1].y);
    67             if (mk[i].end) {
    68                 pos.erase(pos.find(MPR(mk[i].x1, 1)));
    69                 pos.erase(pos.find(MPR(mk[i].x2, -1)));
    70             } else {
    71                 pos.insert(MPR(mk[i].x1, 1));
    72                 pos.insert(MPR(mk[i].x2, -1));
    73             }
    74         }
    75         if (pos.size()) {
    76             puts("shit!");
    77             while (1) {}
    78         }
    79         printf("%.2f
    ", area);
    80     }
    81     return 0;
    82 }
    View Code

    ——written by Lyon

  • 相关阅读:
    bzoj2395: [Balkan 2011]Timeismoney
    bzoj2725: [Violet 6]故乡的梦&&bzoj4400: tjoi2012 桥
    bzoj3047: Freda的传呼机&bzoj2125: 最短路
    bzoj2734: [HNOI2012]集合选数
    bzoj2728: [HNOI2012]与非
    bzoj2730: [HNOI2012]矿场搭建
    bzoj2727: [HNOI2012]双十字
    蓝桥杯-计蒜客之节假日
    蔡基姆拉尔森计算公式
    最长公共子串与最长公共子序列
  • 原文地址:https://www.cnblogs.com/LyonLys/p/hdu_1255_Lyon.html
Copyright © 2011-2022 走看看