Problem - 1255

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

代码如下:

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <set> using namespace std; typedef pair<double, int> PDBI;
multiset<PDBI> pos;
#define MPR make_pair
#define FI first
#define SE second
const int N = ;
double rec[N][]; struct Mark {
double x1, x2, y;
bool end;
Mark() {}
Mark(double x1, double x2, double y, bool end) :
x1(x1), x2(x2), y(y), end(end) {}
bool operator < (Mark x) const { return y < x.y;}
} mk[N << ]; int main() {
int n, T;
cin >> T;
while (T-- && cin >> n) {
for (int i = ; i < n; i++) {
for (int j = ; j < ; j++) {
cin >> rec[i][j];
}
if (rec[i][] > rec[i][]) swap(rec[i][], rec[i][]);
if (rec[i][] > rec[i][]) swap(rec[i][], rec[i][]);
mk[i << ] = Mark(rec[i][], rec[i][], rec[i][], false);
mk[i << | ] = Mark(rec[i][], rec[i][], rec[i][], true);
}
sort(mk, mk + (n << ));
pos.clear();
if (mk[].end) {
puts("WTF?!!");
while () {}
}
pos.insert(MPR(mk[].x1, ));
pos.insert(MPR(mk[].x2, -));
multiset<PDBI>::iterator msi;
double area = 0.0;
for (int i = , end = n << ; i < end; i++) {
msi = pos.begin();
int cnt = ;
double last, sum = 0.0;
while (msi != pos.end()) {
double fi = (*msi).FI;
int se = (*msi).SE;
if (se > ) {
cnt++;
if (cnt == ) last = fi;
} else {
cnt--;
if (cnt == ) sum += fi - last;
}
msi++;
}
area += sum * (mk[i].y - mk[i - ].y);
if (mk[i].end) {
pos.erase(pos.find(MPR(mk[i].x1, )));
pos.erase(pos.find(MPR(mk[i].x2, -)));
} else {
pos.insert(MPR(mk[i].x1, ));
pos.insert(MPR(mk[i].x2, -));
}
}
if (pos.size()) {
puts("shit!");
while () {}
}
printf("%.2f\n", area);
}
return ;
}

——written by Lyon

hdu 1255 覆盖的面积 (Bruceforce)的更多相关文章

  1. hdu 1255 覆盖的面积(线段树 面积 交) (待整理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 Description 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积.   In ...

  2. hdu 1255 覆盖的面积(求覆盖至少两次以上的面积)

    了校赛,还有什么途径可以申请加入ACM校队?  覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  3. HDU - 1255 覆盖的面积(线段树求矩形面积交 扫描线+离散化)

    链接:线段树求矩形面积并 扫描线+离散化 1.给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 2.看完线段树求矩形面积并 的方法后,再看这题,求的是矩形面积交,类同. 求面积时,用被覆 ...

  4. hdu 1255 覆盖的面积 (线段树处理面积覆盖问题(模板))

    http://acm.hdu.edu.cn/showproblem.php?pid=1255 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memo ...

  5. HDU 1255 覆盖的面积(线段树+扫描线)

    题目地址:HDU 1255 这题跟面积并的方法非常像,仅仅只是须要再加一个变量. 刚開始我以为直接用那个变量即可,仅仅只是推断是否大于0改成推断是否大于1.可是后来发现了个问题,由于这个没有下放,没延 ...

  6. hdu 1255 覆盖的面积 (扫描线求矩形交)

    覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  7. HDU 1255 覆盖的面积 ( 扫描线 + 离散 求矩阵大于k次面积并 )

    覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  8. HDU 1255 覆盖的面积(线段树:扫描线求面积并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 题目大意:给你若干个矩形,让你求这些矩形重叠两次及以上的部分的面积. 解题思路:模板题,跟HDU ...

  9. HDU 1255 覆盖的面积 (线段树+扫描线+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 题意很清楚,就是让你求矩阵之间叠加层数大于1的矩形块的面积和. 因为n只有1000,所以我离散化 ...

随机推荐

  1. 问题解决:在js中绑定onclick事件为什么不加括号,在html代码中必须要加?(转载)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. Poj 2104区间第k大(归并树)

    题目链接 K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 36890 Accepted: 11860 C ...

  3. ACdream 1101 线段树

    题目链接 瑶瑶想要玩滑梯 Time Limit: 10000/5000MS (Java/Others)Memory Limit: 512000/256000KB (Java/Others) Submi ...

  4. _STORAGE_WRITE_ERROR_:./Application/Runtime/Cache/Home/f8995a0e1afcdadc637612fae5a3b585.php

    将one think部署到服务器上出现下面的问题 _STORAGE_WRITE_ERROR_:./Application/Runtime/Cache/Home/f8995a0e1afcdadc6376 ...

  5. LintCode刷题笔记-- Maximal Square

    标签:动态规划 题目描述: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing a ...

  6. LintCode刷题笔记-- BackpackII

    标记: 动态规划 问题描述: Given n items with size Ai, an integer m denotes the size of a backpack. How full you ...

  7. MS17-010远程溢出漏洞 - 永恒之蓝 [CVE-2017-0143]

    MS17-010远程溢出漏洞(永恒之蓝) Ti:2019-12-25 By:Mirror王宇阳 MS17-010 CVE-2017-0143 MS17-010 CVE-2017-0144 MS17-0 ...

  8. transform的兼容性写法

    大多数浏览器都有自己的私有前缀,IE的私有前缀是 -ms- 但是大多数CSS3属性对IE低版本就不友好了,所以一般IE9+才能用上transform:rotate(7deg); -ms-transfo ...

  9. python ndarray相关操作:拼接

  10. Leetcode766.Toeplitz Matrix托普利茨矩阵

    如果一个矩阵的每一方向由左上到右下的对角线上具有相同元素,那么这个矩阵是托普利茨矩阵. 给定一个 M x N 的矩阵,当且仅当它是托普利茨矩阵时返回 True. 示例 1: 输入: matrix = ...