http://www.lydsy.com/JudgeOnline/problem.php?id=1628 http://www.lydsy.com/JudgeOnline/problem.php?id=1683 又是重复的题.... 单调栈维护递减,然后相同的话矩形-1 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream&g…
还以为是dp呢 首先默认答案是n 对于一个影子,如果前边的影子比它高则可以归进前面的影子,高处的一段单算: 和他一样高的话就不用单算了,ans--: 否则入栈 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=50005; int n,m,ans,top,h[N],s[N]; int read() { int r=0,f=1; char p=g…
http://www.lydsy.com/JudgeOnline/problem.php?id=1645 这题的方法很奇妙啊...一开始我打了一个“离散”后的线段树.............果然爆了..(因为压根没离散) 这题我们可以画图知道,每2个点都有一个区间,而这个区间的高度是一样的,因此,我们只需要找相邻的两个点,用他们的距离×这个区间的高度就是这块矩形的面积. 将所有这样的矩形累计起来就是答案了. 因此线段树就离散到了O(n)的大小..真神.. 只需要维护点的位置,然后维护区间最值即可…
1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 256  Solved: 210[Submit][Status] Description The best part of the day for Farmer John's cows is when the sun sets. They can see the skyline of the distant city. Bessie w…
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…
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,…
[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=1628 题意: 题解: 单调栈. 单调性: 栈内元素高度递增. 一旦出现比栈顶小的元素,则表明一栋房子的结束. 入栈: 如果出现了一个新的高度b(栈中没有),则入栈. 表明从现在开始,一定有一栋高度为b的房子,只是我们不知道它在哪里结束而已. 出栈: 对于现在的高度b,将栈中所有高度 > b的元素都出栈. 因为此时比b高的房子不得不结束. 每出栈一个元素,ans++. 注:最后要再多算一次…
传送门 从左到右扫一遍,考虑什么时候会和之前形成同一幢房子从而不用统计 显然是当前的高度和之前某个点高度相同,并且它们之间没有更矮的建筑 考虑用一个单调栈维护一个单调上升的房子轮廓,然后对于扫到的每一个高度,看看栈里有没有相同的高度就行了 但是我比较傻逼,没想到,所以用 $set$ 去维护单调栈就可以维护的东西... 每个位置进出 $set$ 一次,复杂度 $O(n \log n)$ #include<iostream> #include<cstdio> #include<a…
Description Input 第一行给出N,W 第二行到第N+1行:每行给出二个整数x,y,输入的x严格递增,并且第一个x总是1 Output 输出一个整数,表示城市中最少包含的建筑物数量 Sample Input 10 26 1 1 2 2 5 1 6 3 8 1 11 0 15 2 17 3 20 2 22 1 INPUT DETAILS: The case mentioned above Sample Output 6   题目的$w$没有意义 我们发现高度$h$出现一次时,答案+1…