题意: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. 传入字典的模型项的类型为“System.Data.Entity.DynamicProxies.

    今天做东西遇到了,这样的一个问题,最后了半天才找到问题所在,现在给大家分享一下问题所在: 传入字典的模型项的类型为“System.Data.Entity.DynamicProxies.doctorUs ...

  2. await, anync

    public Form1() { InitializeComponent(); } // The following method runs asynchronously. The UI thread ...

  3. Xml序列化自引用/循环引用问题1

    1.定义类 public class Student { public int ID { get; set; } public string Name { get; set; } //[XmlIgno ...

  4. c# 预处理命令

    在编译之前进行的处理. 预处理命令以符号“#”开头. #define 只能 定义符号 不能定义宏(#define PI 3.14 这是错的,在c#中没宏) #region #endregion #if ...

  5. .NET 编译器(”Roslyn“)介绍

    介绍 一般来说,编译器是一个黑箱,源代码从一端进入,然后箱子中发生一些奇妙的变化,最后从另一端出来目标文件或程序集.编译器施展它们的魔法,它们必须对所处理的代码进行深入的理解,不过相关知识不是每个人都 ...

  6. JAVA为什么会空指针异常

    1.所谓的指针,就是java中的对象的引用.比如String s;这个s就是指针. 2.所谓的空指针,就是指针的内容为空,比如上面的s,如果令它指向null,就是空指针. 3.所谓的空指针异常,就是一 ...

  7. 如何在苹果官网下载旧版本的Xcode 方法

    1   在百度里输入“苹果开发者中心“,进入以下页面.点击页面中的“Member Center" 2  出现登录界面.这是需要苹果开发者帐号的,没有帐号的可以选择“Create Apple ...

  8. Python 快捷键

    Ctrl + [ .Ctrl + ] 缩进代码Alt+3 Alt+4 注释.取消注释代码行Alt+5 Alt+6 切换缩进方式 空格<=>TabAlt+/ 单词完成,只要文中出现过,就可以 ...

  9. Java反射 - 2(对象复制,父类域,内省)

    为什么要复制对象?假设有个类Car,包含name,color2个属性,那么将car1对象复制给car2对象,只需要car2.setName(car1.getName)与car2.setColor(ca ...

  10. 高级应用与部署 —— 主程序与web目录分离

    在网站部署中,考虑网站的安全行问题,可以将您的网站主程序与web目录分离,使主程序在web目录之外,从而提高网站的安全性. 分离方法 1.将phpcms v9中程序主框架目录phpcms移动至web目 ...