题意:rt 求面积......不计算重复面积(废话。。)hdu1255 的弱化版,应该先做这道题在做那道题的。

************************************************************

#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std; #define Lson r<<1
#define Rson r<<1|1 const int MAXN = 1e5+; struct segmentTree
{///cover记录本区间是否被覆盖,len记录被覆盖的长度
    int L, R, cover;
    double len;
    int mid(){return (L+R)>>;}
}a[MAXN<<];
double Hash[MAXN]; int nh;///记录离散化后的数据
///记录矩形的y边,dir等1表示左边, -1表示右边
struct Edge{double x, y1, y2; int dir;}e[MAXN];
bool cmp(Edge n1, Edge n2)
{///把边按照x从小往大排序
    return n1.x < n2.x;
}
///求y边的长度
double FindEgeLen(int y1, int y2)
{///y1 < y2
    return Hash[y2] - Hash[y1];
}
void BuildSegTree(int r, int L, int R)
{///建立紧密线段树
    a[r].L = L, a[r].R = R;
    a[r].len = a[r].cover = ;     if(L == R-)return ;     BuildSegTree(Lson, L, a[r].mid());
    BuildSegTree(Rson, a[r].mid(), R);
}
void PushUp(int r)
{
    if(a[r].cover)
        a[r].len = FindEgeLen( a[r].L, a[r].R );
    else if(a[r].L == a[r].R-)
        a[r].len = ;
    else
        a[r].len = a[Lson].len + a[Rson].len;
}
void UpData(int r, int L, int R, int dir)
{
    if(a[r].L == L && a[r].R == R)
    {
        a[r].cover += dir;
        PushUp(r);         return ;
    }     if(R <= a[r].mid())
        UpData(Lson, L, R, dir);
    else if(L >= a[r].mid())
        UpData(Rson, L, R, dir);
    else
    {
        UpData(Lson, L, a[r].mid(), dir);
        UpData(Rson, a[r].mid(), R, dir);
    }     PushUp(r);
} int main()
{
    int i, N, t=;     while(scanf("%d", &N), N)
    {
        double x1, x2, y1, y2, area=; int k = ; nh = ;         for(i=; i<N; i++)
        {
            scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
            e[k].x=x1, e[k].y1=y1, e[k].y2=y2, e[k++].dir=;
            e[k].x=x2, e[k].y1=y1, e[k].y2=y2, e[k++].dir=-;
            Hash[nh++] = y1, Hash[nh++] = y2;
        }         sort(Hash, Hash+nh);
        nh = unique(Hash, Hash+nh)-Hash;         BuildSegTree(, , nh-);         sort(e, e+k, cmp);         for(i=; i<k-; i++)
        {
            int L = lower_bound(Hash, Hash+nh, e[i].y1)-Hash;
            int R = lower_bound(Hash, Hash+nh, e[i].y2)-Hash;             UpData(, L, R, e[i].dir);             area += a[].len * (e[i+].x - e[i].x);
        }         printf("Test case #%d\n", t++);
        printf("Total explored area: %.2f\n\n", area);
    }     return ;
}

P - Atlantis - hdu1542(求面积)的更多相关文章

  1. hdu1542 Atlantis 线段树--扫描线求面积并

    There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...

  2. HDU 1542 Atlantis(线段树面积并)

     描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...

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

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

  4. HDU 1542 Atlantis(矩形面积并)

    HDU 1542 Atlantis 题目链接 题意:给定一些矩形,求面积并 思路:利用扫描线,因为这题矩形个数不多,直接暴力扫就能够了.假设数据大.就要用线段树 代码: #include <cs ...

  5. poj 3348--Cows(凸包求面积)

    链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:  ...

  6. HDU1542矩形面积并

    取出纵向边按x坐标排序,在y方向上建立线段树. 每次查询当前有效长度len,ans += len*(x[i]-x[i-1]); 其中len为T[rt].len; 查询完毕后更新y方向上线段树,入边+1 ...

  7. 编写一个矩形类,私有数据成员为矩形的长( len)和宽(wid),wid设置为0,有参构造函数设置和的值,另外,类还包括矩形的周长、求面积、取矩形的长度、取矩形的长度、取矩形的宽度、修改矩形的长度和宽度为对应的形参值等公用方法。

    class Rectangle { private double len, wid; public Rectangle()//求矩形周长 { len = 0; wid = 0; } public Re ...

  8. HDU - 1255 覆盖的面积 (线段树求面积交)

    https://cn.vjudge.net/problem/HDU-1255 题意 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 分析 求面积并的题:https://www.cnbl ...

  9. 覆盖的面积 HDU - 1255(扫描线求面积交)

    题意: 就是扫描线求面积交 解析: 参考求面积并.... 就是把down的判断条件改了一下..由w > 0 改为 w > 1 同时要讨论一下 == 1 时  的情况, 所以就要用到一个临时 ...

随机推荐

  1. 怎样将关系型数据表转换至hbase数据表

    首先须要把关系型数据库的数据表的数据添加由 "纵向延伸",转变为HBase数据表的"横向延伸" 一.Hbase的存储结构 a)      HBase以表(HTa ...

  2. Scala学习笔记之:tuple、array、Map

    [TOC] 本文<快学Scala>的笔记 tuple学习笔记 tuple的定义 对偶是元组(tuple)的最简单形态--元组是不同类型的值的聚集. 元组的值是通过将单个值包含在圆括号中构成 ...

  3. js中的for...in循环机制

    1) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.o ...

  4. Topcoder SRM 637 (Div.2)

    A.GreaterGameDiv2 不能更水 #line 7 "GreaterGameDiv2.cpp" #include<cstdio> #include <c ...

  5. 递归---NYOJ-90整数划分(一)

    这个题理解了好大会才理解,看了网上的代码,不太理解,但是后来看了好几个人的, 大同小异吧,慢慢的就理解了. 思路: 递归函数的意思是, 将 n 划分为最大数为 m 的划分数, 可以分几种情况 1. 当 ...

  6. MaraDNS与DeadWood一起配置为本地机器提供小型化DNS服务

    因为工作测试需要,要在本机装一个环境,可以解析自己命名的域名,即域名->IP的映射服务.在网上找了下,都说是MaraDNS不错.也试了下,在本地配置是没有问题的.从官网上下载的是2-0-11.w ...

  7. mockito学习

    mockito学习 写一个测试用例,如果在测试类上面添加了注解@RunWith(SpringJUnit4ClassRunner.class),必须添加@ContextConfiguration(&qu ...

  8. HTML5新增的属性和废除的属性

    HTML5中,在新增加和废除很多元素的同时,也增加和废除了很多属性. 新增的属性 1.表单相关的属性 对input(type=text).select.textarea与button指定autofoc ...

  9. 【转】Mysql三种备份详解

    一.备份的目的 做灾难恢复:对损坏的数据进行恢复和还原需求改变:因需求改变而需要把数据还原到改变以前测试:测试新功能是否可用 二.备份需要考虑的问题 可以容忍丢失多长时间的数据:恢复数据要在多长时间内 ...

  10. iOS 改变UITextField中光标颜色

    第一种: [[UITextField appearance] setTintColor:[UIColor blackColor]]; 这个方法会影响整个app的所有UITextFiled... 第二种 ...