xtu数据结构 H. City Horizon】的更多相关文章

H. City Horizon Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main   Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful si…
[POJ3277]City Horizon 试题描述 Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings. The entire horizon is represented by a numb…
POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 5077 Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silho…
http://poj.org/problem?id=3277 City Horizon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15255   Accepted: 4111 Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and o…
BZOJ_1654_[Usaco2007 Open]City Horizon 城市地平线_扫描线 Description N个矩形块,交求面积并. Input * Line 1: A single integer: N * Lines 2..N+1: Input line i+1 describes building i with three space-separated integers: A_i, B_i, and H_i Output * Line 1: The total area,…
P2061 [USACO07OPEN]城市的地平线City Horizon 扫描线 扫描线简化版 流程(本题为例): 把一个矩形用两条线段(底端点的坐标,向上长度,添加$or$删除)表示,按横坐标排序 $upd:$本题的底端点坐标简化为$(x,0)$ 蓝后对纵坐标建一棵线段树(本题需要对高度进行离散化). 每次对线段树进行覆盖$or$删除区间操作,顺便统计一下$k=$有多少点被覆盖到 而两次(线段)操作之间的长度为$r=x_{i}-x_{i-1}$ 于是两条线段之间被覆盖的面积即为$k*r$ (…
[BZOJ1645][Usaco2007 Open]City Horizon 城市地平线 Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings. The entire ho…
http://www.lydsy.com/JudgeOnline/problem.php?id=1645 这题的方法很奇妙啊...一开始我打了一个“离散”后的线段树.............果然爆了..(因为压根没离散) 这题我们可以画图知道,每2个点都有一个区间,而这个区间的高度是一样的,因此,我们只需要找相邻的两个点,用他们的距离×这个区间的高度就是这块矩形的面积. 将所有这样的矩形累计起来就是答案了. 因此线段树就离散到了O(n)的大小..真神.. 只需要维护点的位置,然后维护区间最值即可…
Code: #include<cstdio> #include<algorithm> #include<string> #define maxn 1030000 #define inf 300000 #define ll long long using namespace std; void setIO(string s) { string in=s+".in"; freopen(in.c_str(),"r",stdin); }…
题目描述 Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings. The entire horizon is represented by a number line with N (1 ≤ N…
学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个push_down 3 注意push_up 写法有点不一样,不过是可以改成一样的. 简单裸题*2 L - Atlantis  HDU - 1542 #include <iostream> #include <cstdio> #include <algorithm> #inclu…
1645: [Usaco2007 Open]City Horizon 城市地平线 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 315  Solved: 157[Submit][Status] Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe t…
Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings. The entire horizon is represented by a number line with N…
来自这两篇博客的总结 http://blog.csdn.net/SunnyYoona/article/details/43938355 http://m.blog.csdn.net/blog/mr_zys/10226425 题目大意 如图所示,在一条水平线上有N个建筑物,建筑物都是长方形的,且可以互相遮盖.给出每个建筑物的左右坐标值Ai,Bi以及每个建筑物的高Hi,需要计算出这些建筑物总共覆盖的面积. 题目数据范围: 建筑物个数N:1 <= N <= 40000 建筑物左右坐标值Ai, Bi:…
http://poj.org/problem?id=3277 线段树,离散化,成段更新 #include <stdio.h> #include <stdlib.h> #define lson l, m, root<<1 #define rson m+1, r, root<<1|1 ; <<)-; ], color[N<<]; long long max(long long x, long long y) { return x>y…
网上还有用unique函数和lowerbound函数离散的方法,可以百度搜下题解就有. 这里给出介绍unique函数的链接:http://www.cnblogs.com/zhangshu/archive/2011/07/23/2115090.html #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <set> /* 题…
题目链接 题意: 给一些矩形,给出长和高,其中长是用区间的形式给出的,有些区间有重叠,最后求所有矩形的面积. 分析: 给的区间的范围很大,所以需要离散化,还需要把y坐标去重,不过我试了一下不去重 也不会出错, 所有的区间都能列出来,只是在查找的时候费点事. 给的矩形相当于在同一水平线上的,也就是y1坐标相当于为0,其他的就和 poj 1151 Atlantis 差不多了. 我写的思路是按照矩形面积并的思路写的: 但是还有另一种方法也是挺简单的,就是把给的矩形按照高从小到大排序,然后依次插入线段树…
标题效果: 每间房子的长度给出阴影(在间隔代表)而高度,求阴影总面积. 解题思路:矩形面积并. 以下是代码: #include <set> #include <map> #include <queue> //#include <math.h> #include <vector> #include <string> #include <stdio.h> #include <string.h> #include &…
算法 线段树 + 离散化 思路 对\((x,y,h)\)的左右端点\(x,y\)进行离散化,离散化前的原值记为\(val[i]\),对每个矩形按高度\(h\)从小到大排序. 设离散化后的端点有\(M\)个,则对如图所示\(M-1\)个规则矩形编号为\([1,M-1]\),可以由\(h_{[i, i+1]}\times(val[i+1] - val[i])\)得出第\(i\)个矩形的面积. 开一颗区间为\([1,M-1]\)的线段树,按\(h\)从小到大依次对线段树区间覆盖,可以保证高的矩形覆盖了…
Description 约翰带着奶牛去都市观光.在落日的余晖里,他们看到了一幢接一幢的摩天高楼的轮廓在地平线 上形成美丽的图案.以地平线为 X 轴,每幢高楼的轮廓是一个位于地平线上的矩形,彼此间可能有 重叠的部分.奶牛一共看到了 N 幢高楼,第 i 幢楼的高度是 Hi,两条边界轮廓在地平线上的坐标是 Ai 到 Bi.请帮助奶牛们计算一下,所有摩天高楼的轮廓覆盖的总面积是多少. Input 第一行一个整数N,然后有N行,每行三个正整数ai.bi.Hi. Output 一个数,数列中所有元素的和.…
B. Get Many Persimmon Trees Time Limit: 1000ms Memory Limit: 30000KB 64-bit integer IO format: %lld      Java class name: Main Submit Status Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in…
简化版的矩形面积并,不用线段树,不用离散化,代码意外的简单 扫描线,这里的基本思路就是把要求的图形竖着切几刀分成许多矩形,求面积并.(切法就是每出现一条与y轴平行的线段都切一刀) 对于每一个切出来的矩形在处理其右边的线段时计算面积的贡献, #include<cstdio> #include<algorithm> #include<set> using namespace std; typedef long long LL; struct Q { int a,b,h; }…
bzoj题面什么鬼啊-- 题目大意:有一个初始值均为0的数列,n次操作,每次将数列(ai,bi-1)这个区间中的数与ci取max,问n次后元素和 离散化,然后建立线段树,每次修改在区间上打max标记即可 #include<iostream> #include<cstdio> #include<map> #include<algorithm> using namespace std; const int N=100005; int n,g[N],tot,a[N…
链接 题意:N个矩形块,交求面积并. 题解 显然对于每个 \(x\),只要求出这个 \(x\) 上面最高的矩形的高度,即最大值 将矩形宽度离散化一下,高度从小到大排序,线段树区间set,然后求和即可 注意它给的矩形区间是 \([L,R)\) 这样在线段树里直接维护 \([L,R)\) 这样的区间即可 #include<bits/stdc++.h> #define REP(i,a,b) for(int i(a);i<=(b);++i) using namespace std; typede…
题目链接 类似求面积并..2Y.. #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> using namespace std; #define LL __int64 #define maxn 40100 #define lson l , m, rt<<1 #define rson m+1, r,rt&…
I. A Simple Tree Problem Time Limit: 3000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main   Given a rooted tree, each node has a boolean (0 or 1) labeled on it. Initially, all the labels are 0. We define this kind of…
D. Necklace Time Limit: 5000ms Memory Limit: 32768KB 64-bit integer IO format: %I64d      Java class name: Main   Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ball has a beautiful value. The balls with the same beauti…
G. Count the Colors Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main     Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your tas…
C. Ultra-QuickSort Time Limit: 7000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Submit Status In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct…
本文来自作者投稿(原作者:小胖儿),原作者是一位2021届本科毕业生,就读于一所双非(非985.非211)院校,在今年2月份的时候,我曾经帮他指导过简历,并且根据他的简历内容帮他提了一些可能会问到的问题. 4月份的时候说是已经通过了阿里的四面,最近又得知已经顺利的拿到了阿里的Offer,非常为他感到高兴.他还顺便总结了一下自己面试经历,介绍了一下自己是如何准备的,也希望能够给大家带来一些帮助. 以下是他的原文内容,我也对其中的部分内容做了些批注. 前言 前两天,我收到了阿里巴巴的暑假实习offe…