【题目链接】

点击打开链接

【算法】

线段树扫描线

推荐一篇比较容易理解的线段树扫描线的文章 : https://blog.csdn.net/u013480600/article/details/22548393

【代码】

注意此题输出格式若使用"%.2lf"会离奇Wrong Answer,要改为"%.2f"

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 110 int i,n,l1,l2,l,L,R,TC;
double xa,ya,xb,yb,area;
double a[MAXN*],x[MAXN*],arr[MAXN*]; struct info {
double l,r,h,opt;
} y[MAXN*]; struct SegmentTree {
struct Node {
int l,r,c;
double m;
} Tree[MAXN*];
inline void build(int index,int l,int r) {
int mid;
Tree[index].l = l;
Tree[index].r = r;
Tree[index].m = 0.0;
Tree[index].c = ;
if (l == r) return;
mid = (l + r) >> ;
build(index<<,l,mid);
build(index<<|,mid+,r);
}
inline void update(int index) {
if (Tree[index].c > ) Tree[index].m = arr[Tree[index].r+] - arr[Tree[index].l];
else if (Tree[index].l == Tree[index].r) Tree[index].m = ;
else Tree[index].m = Tree[index<<].m + Tree[index<<|].m;
}
inline void add(int index,int l,int r,int val) {
int mid;
if (Tree[index].l == l && Tree[index].r == r) {
Tree[index].c += val;
update(index);
return;
}
mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= r) add(index<<,l,r,val);
else if (mid + <= l) add(index<<|,l,r,val);
else {
add(index<<,l,mid,val);
add(index<<|,mid+,r,val);
}
update(index);
}
inline double query() {
return Tree[].m;
}
} T; bool cmp(info a,info b) { return a.h > b.h; } int main() { while (scanf("%d",&n) != EOF && n) {
l = l1 = l2 = ;
for (i = ; i <= n; i++) {
scanf("%lf%lf%lf%lf",&xa,&ya,&xb,&yb);
x[++l1] = xa;
x[++l1] = xb;
y[++l2] = (info){xa,xb,ya,-};
y[++l2] = (info){xa,xb,yb,};
}
sort(x+,x+l1+);
x[] = -;
for (i = ; i <= l1; i++) {
if (x[i] != x[i-])
arr[++l] = x[i];
}
T.build(,,l-);
sort(y+,y+l2+,cmp);
area = 0.0;
for (i = ; i < l2; i++) {
L = lower_bound(arr+,arr+l+,y[i].l) - arr;
R = lower_bound(arr+,arr+l+,y[i].r) - arr - ;
T.add(,L,R,y[i].opt);
area += T.query() * (y[i].h - y[i+].h);
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",++TC,area);
} return ; }

【POJ 1151】 Altlantis的更多相关文章

  1. 【POJ 1151】Atlantis

    离散化后扫描线扫一遍. 夏令营时gty学长就讲过扫描线,可惜当时too naive,知道现在才写出模板题. 当时也不会线段树啊233 #include<cstdio> #include&l ...

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. codevs——1501 二叉树最大宽度和高度

    1501 二叉树最大宽度和高度  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解       题目描述 Description 给出一个二叉树,输出它的 ...

  2. linux find grep 查找命令

    原文:fhqdddddd.blog.163.com/blog/static/186991542012417105729415/ find 1.作用 find命令的作用是在目录中搜索文件,它的使用权限是 ...

  3. VS调试时不加载符号

    加载符号,能够让调试时进入系统的dll中,甚至能达到汇编语言的深度,让你调试时能够逐行进行.但是加载符号的话,会使得每次调试,增加进入到首个断点的时间. 而且有时候也非必要加载符号,它的取消可以使用下 ...

  4. gdb源码安装过程中的问题:no termcap library found

    gdb使用源码安装的时候遇到错误:no termcap library found ./configure -->  make --> make install 解决办法,下载termca ...

  5. electron 开发拆坑总结

    electron 总结 前言 有一个web项目需要用客户端来包装一下 项目的主要业务都在服务器上 所以项目的大多数功能都用url 地址来访问: 客户端登陆界面在本地 打包客户端的本地登陆界面 做为登陆 ...

  6. NAND FLash基础概念介绍

    一.引脚介绍 引脚名称 引脚功能 CLE 命令锁存功能 ALE 地址锁存功能 /CE 芯片使能 /RE 读使能 /WE 写使能 /WP 写保护 R/B 就绪/忙输出信号 Vcc 电源 Vss 地 N. ...

  7. 8. Smarty3:模版中的内置函数

    smarty3中对内置函数的修改比較大,加入了很多新的功能:变量声明.表达式,流程控制,函数.数组等.可是建议不要在模版中去使用过于复杂的逻辑,而是要尽量将一些程序设计逻辑写到PHP中,并在模版中採用 ...

  8. Struts2学习(二)运行Action中方法的三种方式

    1.运行execute()方法 一般的能够直接在action中书写execute,调用action时会自己主动运行此方法 2.配置method方法 在struts.xml中配置action时.写met ...

  9. 一篇很好的讲解SIFT算法的文章

    http://blog.csdn.net/zddblog/article/details/7521424

  10. Django-配置celery

    首先需要安装的包 pip install cellerypip install django-cellery pip install django-cellery-results pip instal ...