POJ 3277 City Horizon【map模板】【stl练习】
来源:互联网 发布:北京通州淘宝运营培训 编辑:程序博客网 时间:2024/06/06 19:31
http://poj.org/problem?id=3277
题目大意:求N个矩形面积并(底固定)
看到网上许多犇们都是线段树+离散化搞,表示太强了啊,蒟蒻只会map。。。
于是便成了一道MAP模板题,维护当前矩形们的最大高度即可。
不嫌麻烦可以写平衡树。。
#include <map>#include <cstdio>#include <algorithm>#include <functional>using namespace std;typedef long long LL;LL ans;int n, x, y, z, tot, lstpos;map<int, int, greater<int> > M;struct hjl_t { int pos, ins, h; } hjl[80005];bool cmppos(hjl_t a, hjl_t b) { return a.pos < b.pos; }int main() {scanf("%d", &n);for (int i = 1; i <= n; ++i) {scanf("%d %d %d", &x, &y, &z);hjl[++tot].h = z;hjl[tot].pos = x;hjl[tot].ins = 1;//左边hjl[++tot].h = z;hjl[tot].pos = y;hjl[tot].ins = 0;//右边}sort(hjl + 1, hjl + tot + 1, cmppos);for (int i = 1; i <= tot; ++i) {if (!M.empty()) ans += LL(M.begin()->first) * LL(hjl[i].pos - lstpos);//M中的最great的那个元素。。if (hjl[i].ins) ++M[hjl[i].h];else if (--M[hjl[i].h] == 0) M.erase(hjl[i].h);lstpos = hjl[i].pos;}printf("%lld\n", ans);}
1 0
- POJ 3277 City Horizon【map模板】【stl练习】
- poj 3277 City Horizon
- poj 3277 City Horizon
- POJ 3277 City Horizon
- poj 3277 City Horizon
- poj 3277 City Horizon
- POJ 3277 City Horizon
- POJ 3277 City Horizon
- POJ 3277 City Horizon
- POJ 3277 City Horizon
- poj 3277 City Horizon
- [POJ 3277]City Horizon
- poj 3277 City Horizon
- POJ 3277 City Horizon
- poj -- 3277City Horizon (线段树)
- poj 3277 city horizon 线段树
- POJ 3277 City Horizon 线段树
- POJ 3277 City Horizon 线段染色
- 关联之组合聚合
- [JZOJ4884]图的半径/[JZOJ4572]Center
- 软件测试(第2版)_Paul学习02_01——Ch1测试概述_01
- SVM中的Karush-Kuhn-Tucker条件和对偶问题
- Effective C++ 学习笔记(六)
- POJ 3277 City Horizon【map模板】【stl练习】
- Java垃圾回收机制
- poj2237 Bad Cowtractors 最大生成树
- STL-set (集合)之删除元素
- [编程之美]写一个函数,返回一个数组中所有元素被第一个元素除的结果
- C#——属性读写
- VS2012 IIS发布.net MVC 网站后无法正常访问
- House Robber(窃贼的计划)
- 穷举接口-将PE作为DLL载入