HDU1255(KB7-O)
覆盖的面积
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7779 Accepted Submission(s): 3923
Problem Description

Input
注意:本题的输入数据较多,推荐使用scanf读入数据.
Output
Sample Input
5
1 1 4 2
1 3 3 7
2 1.5 5 4.5
3.5 1.25 7.5 4
6 3 10 7
3
0 0 1 1
1 0 2 1
2 0 3 1
Sample Output
0.00
Author
//2018-09-09
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lson (id<<1)
#define rson ((id<<1)|1)
using namespace std; const int N = ;
const double EPS = 0.0001; struct Node{
double sum;
}tree[N<<];
int cnt[N], len;
double x[N]; void build(){
memset(tree, , sizeof(tree));
} void update(int id, int L, int R, int pos, int val){
if(L==R){
cnt[pos] += val;
if(cnt[pos]>)tree[id].sum = x[pos+]-x[pos];
else tree[id].sum = ;
return;
}
int mid = (L+R)/;
if(pos <= mid)update(lson, L, mid, pos, val);
else update(rson, mid+, R, pos, val);
tree[id].sum = tree[lson].sum+tree[rson].sum;
} struct Line{
double x0, x1, y;
int fg;
bool operator<(const Line l) const{
return y < l.y;
}
}line[N<<]; int bsearch(int l, int r, int key){
while(l < r){
int mid = (l+r)>>;
if(key <= x[mid])r = mid;
else l = mid+;
}
return l;
} int main()
{
int T, n, kase = ;
scanf("%d",&T);
while(T--){
scanf("%d", &n);
double x0, y0, x1, y1;
len = ;
for(int i = ; i <= n; i++){
scanf("%lf%lf%lf%lf", &x0, &y0, &x1, &y1);
int a = i*-, b = i*;
line[a].x0 = x0, line[a].x1 = x1, line[a].y = y0, line[a].fg = ;
line[b].x0 = x0, line[b].x1 = x1, line[b].y = y1, line[b].fg = -;
x[++len] = x0, x[++len] = x1;
}
n*=;
sort(x+, x++n);
sort(line+, line++n);
memset(cnt, , sizeof(cnt));
build();
double ans = ;
for(int i = ; i <= n; i++){
ans += tree[].sum*(line[i].y-line[i-].y);
int l = lower_bound(x+, x++n, line[i].x0)-x;
int r = lower_bound(x+, x++n, line[i].x1)-x;
for(int j = l; j < r; j++){
update(, , n-, j, line[i].fg);
}
}
printf("%.2lf\n", ans+EPS);
} return ;
}
HDU1255(KB7-O)的更多相关文章
- 扫描线专题 hdu1255
hdu1255 求覆盖至少两次的面积,和直接求覆盖面积比,就是保证cover>1就可以了. 没有进行lazy操作,因为每一次更新伴随着询问,感觉没有必要.982MS水过. #include &l ...
- HDU1255覆盖的面积
覆盖的面积 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- HDU1255 覆盖的面积 —— 求矩形交面积 线段树 + 扫描线 + 离散化
题目链接:https://vjudge.net/problem/HDU-1255 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. Input输入数据的第一行是一个正整数T(1<= ...
- hdu1255 矩阵的交 线段树+扫描线
/* 不是叶子节点 ,且cnt=1.注意这里,cnt=1确切的意义是什么, 应该是,可以确定,这个区间被完全覆盖了1次, 而有没有被完全覆盖两次或以上则不知道无法确定,那么怎么怎么办了, 只要加上t[ ...
- HDU-1255 覆盖的面积 (扫描线)
题目大意:给若干个矩形,统计重叠次数不为0的面积. 题目分析:维护扫描线的长度时,只需要只统计覆盖次数大于1的区间即可.这是个区间更新,不过不能使用懒标记,但是数据规模不大,不用懒惰标记仍可以AC. ...
- HDU-1255 覆盖的面积 覆盖的矩形面积并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 需要保存区间覆盖线>=2的线段的长度,根据情况来更新... //STATUS:C++_AC ...
- hdu1255(线段树——矩形面积交)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 题意:求N个矩形中,求被覆盖至少俩次的面积和 分析:覆盖两次即col[rt]>=2就好.一 ...
- hdu1255 覆盖的面积 线段树+里离散化求矩形面积的交
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 求矩形面积的交的线段树题目,刚做了求并的题目,再做这个刚觉良好啊,只要再加一个表示覆盖次数大于1 ...
- hdu1255扫描线计算覆盖两次面积
总体来说也是个模板题,但是要开两个线段树来保存被覆盖一次,两次的面积 #include<iostream> #include<cstring> #include<cstd ...
随机推荐
- ZKWeb网页框架2.1正式发布
2.1.0更新的内容有 更新引用类库 NHibernate 5.1.0 Npgsql 3.2.7 MySqlConnector 0.37.0 Dapper 1.50.4 Dommel 1.10.1 Z ...
- mfcc的特征提取python 代码实现和解析
#!/usr/bin/python # -*- coding: UTF-8 -*- import numpy import scipy.io.wavfile from matplotlib impor ...
- HOG算法资源备忘
最近再研究这个算法,找了不少资料来研究,发现这方面的资料好的并不多,今天就把找到的经典的资料做一个汇总,方便后续查阅吧. 一 基本概念和推导: 1 解释最清楚的:中文网站:https://blog.c ...
- Python中的注释和解注释
注释 目标 注释的作用 单行注释(行注释) 多行注释(块注释) 01. 注释的作用 使用用自己熟悉的语言,在程序中对某些代码进行标注说明,增强程序的可读性 02. 单行注释(行注释) 以 # 开头,# ...
- Spring Boot 2.x 启动全过程源码分析(上)入口类剖析
Spring Boot 的应用教程我们已经分享过很多了,今天来通过源码来分析下它的启动过程,探究下 Spring Boot 为什么这么简便的奥秘. 本篇基于 Spring Boot 2.0.3 版本进 ...
- Elasticsearch基础教程分享
基础及相关资料 首先我们先了解一下什么是Elastisearch,Elasticsearch(简称es)是一个基于Lucene库的搜索引擎.它提供了一个分布式.支持多租户的全文搜索引擎,具有HTTP ...
- equalsIgnoreCase()和equals()的区别
String a="ABC";a.equals("abc")为false,a.equalsIgnoreCase("abc")为true;eq ...
- MySQL(5)---锁
锁 一概述 数据库锁定机制简单来说,就是数据库为了保证数据的一致性,而使各种共享资源在被并发访问变得有序所设计的一种规则.对于任何一种数据库来说都需要有相应的锁定机制. MySQL各存储引擎使用了三种 ...
- 通过appium-desktop定位元素
https://www.cnblogs.com/feng0815/p/8481679.html http://www.cnblogs.com/feng0815/p/8481495.html appiu ...
- Java——this关键字
前言 this关键字属于Java中比较复杂的关键字之一,若是学习过C++或者其他的一些面向对象语言也会遇到this这个关键字并且都会看到this的含义就是表示当前对象.什么叫做表示当前对象?this在 ...