题意: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. js正则表达式中的问号使用技巧总结

    这篇文章主要介绍了js正则表达式中的问号几种用法,比如+?,*?,{2,3}?可以停止匹配的贪婪模式等例子的解析. 在表示重复的字符后面加问号,比如+?,*?,{2,3}?可以停止匹配的贪婪模式. v ...

  2. JavaScript arguments类数组

    1. 什么是类数组 arguments 是一个类数组对象.代表传给一个function的参数列表.  我们来传一个实例. function printArgs() { console.log(argu ...

  3. SharedPreferences的工具类,使用起来方便、快捷

    SharedPreferences的工具类,使用起来方便.快捷:上代码:import android.content.Context;import android.content.SharedPref ...

  4. 关于lower_bound()的用法--NYOJ 201作业题

    lower_bound它有三个参数, 第一个和第二个是给定区间起点和终点的指针,第三个参数是要查找的数,它的作用原理是在给定的区间中进行二分查找,这个二分区间是前开后闭的,他返回第一个大于等于它的函数 ...

  5. 第1章 你真的了解C#吗?

    什么是C#? C#是由微软公司开发的一种面向对象且运行于.Net Framework之上的高级程序设计语言,发布于2000年6月. 什么是.Net Framework 我们可以这样去理解.Net Fr ...

  6. 使用静态资源设置UI信息

    首先建立一个文件存放样式设置(资源字典),所有风格设置都可以这里进行 加入以下代码: <ResourceDictionary xmlns="http://schemas.microso ...

  7. mssql SUBSTRING和charindex的用法

    在工作中用到的例子: select * FROM [CSGDC.DataETLDB].[dbo].[StrategiesList] where strategy_name like '%基建系统%' ...

  8. vsftp关于"550 create directory operation failed"问题解决

    前提: 昨天晚上配置好了vsftp, 但登陆后,除了浏览,什么也干不了.(如新建文件/文件夹, 删除文件, 重命名等都不可操作) 都是弹出 "550 create directory ope ...

  9. rsync从windows到linux的同步备份

    名称 角色 IP地址 Windows server 2003 服务器 Eth0:192.168.1.1 RHEL5.5 客户端 Eth0:192.168.1.2   一.cwRsyncServer服务 ...

  10. 如何安装Git到MAC OS X

    这里介绍两种方式:一,使用Git command-line二,使用GUI工具SourceTree,功能很强大,很方便 在进行安装前,要说一下,Git和SVN一样,都需要创建一个服务器的,他们都可以创建 ...