离散化后扫描线扫一遍。

夏令营时gty学长就讲过扫描线,可惜当时too naive,知道现在才写出模板题。

当时也不会线段树啊233

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 103; struct node {
double x1, x2, y; int d;
node (double _x1 = 0, double _x2 = 0, double _y = 0, int _d = 0) : x1(_x1), x2(_x2), y(_y), d(_d) {}
} L[N << 1];
bool cmp(node A, node B) {return A.y < B.y;}
int n, m, lazy[N << 3], cnt;
double X[N << 2], sum[N << 3];
int find(double x) {
int left = 1, right = n, mid;
while (left <= right) {
mid = (left + right) >> 1;
if (X[mid] == x) return mid;
else if (X[mid] > x) right = mid - 1;
else left = mid + 1;
}
}
void pushup(int rt, int l, int r) {
if (lazy[rt]) sum[rt] = X[r + 1] - X[l];
else if (l == r) sum[rt] = 0;
else sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
void add(int rt, int l, int r, int L, int R, int s) {
if (L <= l && r <= R) {
lazy[rt] += s;
pushup(rt, l, r);
return;
}
int mid = (l + r) >> 1;
if (L <= mid) add(rt << 1, l, mid, L, R, s);
if (R > mid) add(rt << 1 | 1, mid + 1, r, L, R, s);
pushup(rt, l, r);
} int main() {
int c = 0, l, r;
double x1, x2, y1, y2, ans;
while (scanf("%d", &m), m) {
memset(sum, 0, sizeof(sum));
memset(lazy, 0, sizeof(lazy));
cnt = 0;
for(int i = 1; i <= m; ++i) {
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
L[++cnt] = node(x1, x2, y1, 1);
X[cnt] = x1;
L[++cnt] = node(x1, x2, y2, -1);
X[cnt] = x2;
}
sort(X + 1, X + cnt + 1);
sort(L + 1, L + cnt + 1, cmp);
n = 1;
for(int i = 2; i <= cnt; ++i)
if (X[i] != X[i - 1]) X[++n] = X[i];
ans = 0;
for(int i = 1; i < cnt; ++i) {
l = find(L[i].x1); r = find(L[i].x2) - 1;
add(1, 1, n, l, r, L[i].d);
ans += sum[1] * (L[i + 1].y - L[i].y);
}
printf("Test case #%d\nTotal explored area: %.2lf\n\n", ++c, ans);
}
return 0;
}

poj上用G++交WA的生活不能自理QAQ,用C++交题大法好~

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

  1. 【POJ 1151】 Altlantis

    [题目链接] 点击打开链接 [算法] 线段树扫描线 推荐一篇比较容易理解的线段树扫描线的文章 : https://blog.csdn.net/u013480600/article/details/22 ...

  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. 使用Windows Azure的VM安装和配置CDH搭建Hadoop集群

    本文主要内容是使用Windows Azure的VIRTUAL MACHINES和NETWORKS服务安装CDH (Cloudera Distribution Including Apache Hado ...

  2. Concurrency::task(C++)

    先看一个例子 #include <ppltasks.h> #include <iostream> using namespace Concurrency; using name ...

  3. [No000021]跟维多利亚学英语

  4. poj2632 Crashing Robots

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9859   Accepted: 4209 D ...

  5. ubuntu为用户增加sudoer权限的两种方法

    方法一.使用usermod命令 新增user sudo adduser username 增加sudo权限 sudo usermod -aG sudo username sudo usermod -a ...

  6. ADB server didn't ACK 问题解决

    在命令行中运行adb shell 出现如下错误提示 C:\Documents and Settings\Administrator>adb shelladb server is out of d ...

  7. 未能正确加载包“Microsoft.Data.Entity.Design.Package.MicrosoftDataEntityDesignPackage

    本文出处:http://blog.sina.com.cn/s/blog_6fe3efa301016i64.html vs 2005 ,vs 2008, vs 2010,安装后有时出现这个错误(我的机器 ...

  8. quartz.net 项目无法加载的问题

    最近尝试试用一下quartz.net 做任务调度用. 下载了源代码后打开解决方案发现项目无法加载.错误如下 未找到导入的项目“C:\Users\****\Desktop\Quartz.NET-2.1. ...

  9. 大数据下多流形聚类分析之谱聚类SC

    大数据,人人都说大数据:类似于人人都知道黄晓明跟AB结婚一样,那么什么是大数据?对不起,作为一个本科还没毕业的小白实在是无法回答这个问题.我只知道目前研究的是高维,分布在n远远大于2的欧式空间的数据如 ...

  10. Webwork 学习之路【02】前端OGNL试练

    1.OGNL 出现的意义 在mvc中,数据是在各个层次之间进行流转是一个不争的事实.而这种流转,也就会面临一些困境,这些困境,是由于数据在不同世界中的表现形式不同而造成的: a. 数据在页面上是一个扁 ...