POJ 1389 (扫描线)
来源:互联网 发布:江阴市网络教研平台 编辑:程序博客网 时间:2024/05/16 05:33
第一题扫描线,连离散化都不用0.0
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>using namespace std;#define maxn 51111#define pl c<<1#define pr (c<<1)|1#define lson tree[c].l,tree[c].mid,c<<1#define rson tree[c].mid+1,tree[c].r,(c<<1)|1struct node { int l, r, mid; int len; int cover;}tree[maxn<<4];struct segment { int l, r, h, flag; bool operator < (segment a) const { return h < a.h; }}p[2222];void build_tree (int l, int r, int c) { //cout << l << " " << r << endl; tree[c].l = l, tree[c].r = r, tree[c].mid = (l+r)>>1; tree[c].len = 0, tree[c].cover = 0; if (l == r) return ; build_tree (lson); build_tree (rson); return ;}void push_up (int c) { if (tree[c].cover) { tree[c].len = (tree[c].r - tree[c].l+1); } else { tree[c].len = tree[pl].len + tree[pr].len; }}void update (int l, int r, int c, int x, int y, int v) { if (x == l && y == r) { tree[c].cover += v; push_up (c); return ; } if (tree[c].mid >= y) update (lson, x, y, v); else if (tree[c].mid < x) update (rson, x, y, v); else { update (lson, x, tree[c].mid, v); update (rson, tree[c].mid+1, y, v); } push_up (c);}int a, b, c, d;int cnt;void add () { c--; p[cnt].l = a, p[cnt].r = c, p[cnt].h = b, p[cnt].flag = 1; cnt++; p[cnt].l = a, p[cnt].r = c, p[cnt].h = d, p[cnt].flag = -1; cnt++;}int main () { //freopen ("in", "r", stdin); while (scanf ("%d%d%d%d", &a, &b, &c, &d) == 4 && a+b+c+d != -4) { cnt = 0; add (); while (scanf ("%d%d%d%d", &a, &b, &c, &d) == 4 && a+b+c+d != -4) { add (); } sort (p, p+cnt); build_tree (0, 50000, 1); long long ans = 0; for (int i = 0; i < cnt-1; i++) { update (0, 50000, 1, p[i].l, p[i].r, p[i].flag); ans += (p[i+1].h - p[i].h) * (long long)tree[1].len; } printf ("%lld\n", ans); } return 0;}
0 0
- POJ 1389 (扫描线)
- POJ 1389 (扫描线)
- poj 1389 扫描线
- POJ 1151 扫描线
- POJ 2932 (扫描线)
- poj 1151 扫描线
- POJ 2932 扫描线思想
- poj 2932 Coneology 扫描线
- poj 1151 Atlantis 扫描线
- poj 3109 扫描线+bit
- POJ 1389 Area of Simple Polygons(扫描线)
- POJ 1389 Area of Simple Polygons 线段树 扫描线
- poj 1151 poj 1389 线段树+扫描线+离散化 [矩形的面积并]
- poj 1151 Atlantis(线段树 扫描线)
- POJ 1151 Atlantis(扫描线)
- 【扫描线法】&& poj 1177 && hdu 1828
- poj 1765 November Rain(扫描线)
- POJ 1151 - Atlantis 线段树+扫描线..
- 前台页面技术之引用 js 与css 方法
- android活动的启动模式
- 关于SqLite的研究
- 好的深度学习——学习地址
- spring mvc 结合jackson返回的日期格式问题
- POJ 1389 (扫描线)
- Android 文件的上传
- 设置界面的搭建和封装
- libvirt的安装流程
- 九度oj-1088-剩下的树
- JDK-Eclipse-Android_SDK-ADT详细图文安装教程(2)
- 设置界面-更新
- Bitmap的相关方法汇总
- int 和Integer创建对象在内存中的初始值不同