HDU 1828 Picture
来源:互联网 发布:伺服电机选型软件 编辑:程序博客网 时间:2024/06/07 08:13
矩形周长并。就是数竖着的区间里,竖边的条数,再加上横边即可。
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<vector>#include<string>#include<queue>#include<cmath>#include<map>///LOOP#define REP(i, n) for(int i = 0; i < n; i++)#define FF(i, a, b) for(int i = a; i < b; i++)#define FFF(i, a, b) for(int i = a; i <= b; i++)#define FD(i, a, b) for(int i = a - 1; i >= b; i--)#define FDD(i, a, b) for(int i = a; i >= b; i--)///INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)#define RFI(n) scanf("%lf", &n)#define RFII(n, m) scanf("%lf%lf", &n, &m)#define RFIII(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)#define RFIV(n, m, k, p) scanf("%lf%lf%lf%lf", &n, &m, &k, &p)#define RS(s) scanf("%s", s)///OUTPUT#define PN printf("\n")#define PI(n) printf("%d\n", n)#define PIS(n) printf("%d ", n)#define PS(s) printf("%s\n", s)#define PSS(s) printf("%s ", s)#define PC(n) printf("Case %d: ", n)///OTHER#define PB(x) push_back(x)#define CLR(a, b) memset(a, b, sizeof(a))#define CPY(a, b) memcpy(a, b, sizeof(b))#define display(A, n, m) {REP(i, n){REP(j, m)PIS(A[i][j]);PN;}}#define lson l, m, rt << 1#define rson m + 1, r, rt << 1 | 1using namespace std;typedef long long LL;typedef pair<int, int> P;const int MOD = 1e9+7;const int INFI = 1e9 * 2;const LL LINFI = 1e17;const double eps = 1e-6;const double pi = acos(-1.0);const int N = 11111;const int M = N << 2;const int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};int X[N], sum[M], num[M], cnt[M];bool lb[M], rb[M];struct node{ int x1, x2, y, k; node(){}; node(int a, int b, int c, int d){x1 = a, x2 = b, y = c, k = d;}; bool operator < (const node a) const { return y < a.y; }}seg[N];void pushup(int l, int r, int rt){ if(cnt[rt]) { lb[rt] = rb[rt] = 1; num[rt] = 2; sum[rt] = X[r + 1] - X[l]; } else if(l == r)sum[rt] = num[rt] = lb[rt] = rb[rt] = 0; else { num[rt] = num[rt << 1] + num[rt << 1 | 1]; sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; lb[rt] = lb[rt << 1]; rb[rt] = rb[rt << 1 | 1]; if(lb[rt << 1 | 1] && rb[rt << 1])num[rt] -= 2; }}void update(int L, int R, int c, int l, int r, int rt){ if(L <= l && r <= R) { cnt[rt] += c; pushup(l, r, rt); return; } int m = (l + r) >> 1; if(L <= m)update(L, R, c, lson); if(R > m) update(L, R, c, rson); pushup(l, r, rt);}int bin(int x, int n){ int l = 0, r = n - 1, m; while(l <= r) { m = (l + r) >> 1; if(X[m] == x)return m; else if(X[m] > x)r = m - 1; else l = m + 1; }}int main(){ //freopen("input.txt", "r", stdin); int n, a, b, c, d, m, k, ans, last; while(RI(n) != EOF) { m = k = ans = last = 0; REP(i, n) { RIV(a, b, c, d); X[m++] = a; X[m++] = c; seg[k++] = node(a, c, b, 1); seg[k++] = node(a, c, d, -1); } sort(X, X + m); sort(seg, seg + k); m = unique(X, X + m) - X; CLR(sum, 0), CLR(num, 0); CLR(lb, 0), CLR(rb, 0); REP(i, k) { a = bin(seg[i].x1, m); b = bin(seg[i].x2, m) - 1; update(a, b, seg[i].k, 0, m - 1, 1); ans += num[1] * (seg[i + 1].y - seg[i].y); c = sum[1] - last; if(c < 0)c = -c; ans += c; last = sum[1]; } PI(ans); } return 0;}
- hdu 1828 Picture
- HDU 1828 - Picture
- HDU 1828 Picture
- hdu 1828 picture
- HDU 1828 Picture
- HDU 1828 Picture
- 【49.23%】【hdu 1828】Picture
- Picture HDU 1828
- HDU 1828 Picture
- hdu 1828 Picture
- hdu 1828 picture 线段树
- hdu 1828 Picture(扫描线)
- HDU-1828-Picture(线段树)
- Picture hdu 1828 扫描线
- hdu 1828 Picture(线段树)
- |Hdu 1828|线段树|Picture
- POJ 1177 Picture & hdu 1828 Picture(扫描线)
- hdu 1828 Picture(矩形周长并)
- strchr函数
- JAVA设计模式学习——命令模式
- iOS7或以后将不能使用MAC地址生成设备的唯一标识
- windows大多数的弹窗提示内容是可以复制的(我们主要用于报错内容复制粘贴去百度)
- opengl 投影矩阵的理解
- HDU 1828 Picture
- 在AS3页游中,快捷菜单组件的封装使用
- 每日学习: 统计数字会说谎
- jsp页面格式化数字或时间
- windows7下cmd命令窗口没有滚动条的解救方法
- 数组全排列算法(一)字符串数组全排列——逐个追加组合算法
- 如何简化游戏ui数据更新
- odbc 读取excel
- ViewPager中有Activity的按键捕获问题