BOI 383

原创 2012年03月24日 22:28:45

Problem A. Ponding Water
Description
There is a strange building on planet VOID. It is made up of N*M
rectangular parallelepipeds on N*M grids, whose bottom surfaces are 1*1
squares. Since heights of these rectangular parallelepipeds are different,
they form a number of “holes” inside the building. After a heavy rainfall
there will be some ponding water in these holes. You are asked to
calculate the maximum possible volume of the ponding water.
Top view of the building
ponding water is painted grey on the right figure


Input
There are multiple cases, end by EOF.
For each case, the first line contains two integers, N and M (1 <= N, M <=
100), length and width of the building respectively. Then N lines followed,
each of which contains M integers (these integers are between [0,
10000]), describing the height of each rectangular parallelepiped.
Output
For each case, you should output one integer in a line, the maximum
possible volume of the ponding water.
Sample Input
3 6
3 3 4 4 4 2
3 1 3 2 1 4
7 3 1 6 4 1
3 3
3 2 3
2 2 2
3 2 3
Sample Ouput
5

0

#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

struct sp
{
	int r, c, h;
	sp() {}
	sp(int x, int y, int z): r(x), c(y), h(z) {}
	bool operator<(const sp &rhs) const
	{
		return h > rhs.h;
	}
};

int R, C;
int h[110][110];
bool vis[110][110];       //vis为1的点表示最外面的墙
int dr[] = {1,0,-1,0};
int dc[] = {0,1,0,-1};
int ans, curh;
priority_queue<sp> heap;

void dfs(int r, int c)
{
	if (r<0||r>=R||c<0||c>=C) return;
	if (vis[r][c]) return;
	vis[r][c] = 1;
	if (curh >= h[r][c])
		ans += curh-h[r][c];
	else{
		heap.push(sp(r, c, h[r][c]));
		return;
	}
	for (int i = 0; i < 4; ++i)
		dfs(r+dr[i], c+dc[i]);
}

int main()
{
	int i, j, k, r, c;
	while (~scanf("%d%d", &R, &C))
	{
		memset(vis, 0, sizeof(vis));
		for (r = 0; r < R; ++r)
			for (c = 0; c < C; ++c)
				scanf("%d", &h[r][c]);
		for (r = 0; r < R; ++r)
		{
			heap.push(sp(r, 0, h[r][0]));
			vis[r][0] = 1;
			heap.push(sp(r, C-1, h[r][C-1]));
			vis[r][C-1] = 1;
		}
		for (c = 1; c < C-1; ++c)
		{
			heap.push(sp(0, c, h[0][c]));
			vis[0][c] = 1;
			heap.push(sp(R-1, c, h[R-1][c]));
			vis[R-1][c] = 1;
		}
		ans = 0;
		sp cur;
		while (!heap.empty())
		{
			cur = heap.top(); heap.pop();
			curh = cur.h;
			for (i = 0; i < 4; ++i)
				dfs(cur.r+dr[i], cur.c+dc[i]);
		}
		printf("%d\n", ans);
	}
	return 0;
}


 


 

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

【分层图】【BOI2007】Fence

题目描述 Leopold is indeed a lucky fellow. He just won a huge estate in the lottery. The estate contains...

【COGS】1752. [BOI2007]摩基亚Mokia cdq分治模板题

传送门:【COGS】1752. [BOI2007]摩基亚Mokia 题目分析:cdq分治的基本运用。 代码如下: #include #include #include using...

C#383-音乐风景壁纸源代码

  • 2017-07-23 20:26
  • 335KB
  • 下载

FT383NT电源管理

  • 2014-06-22 10:47
  • 264KB
  • 下载

JZOJ 【BOI2012】Peaks

题意就不说了。分析:一看就是经典套路,一般来讲思路就是先建图然后二分,然后细节比较多。 先把平原都缩点,不然会爆。然后因为让你求任意两个山峰之间的最小值最大,那就做kruskal最大生成树,然后每次...

【BOI2012】Mobile

Description平面上有一条线段,从(0,0)到(L,0) 有N个点,求线段上任意一点到这N个点中最近点的距离的最大值 换言之,求一个半径,使得以这N个点为圆心所成的圆能覆盖整条线段 1<...

cogs 1752. [BOI2007]摩基亚Mokia

题目链接:http://www.cogs.pro/cogs/problem/problem.php?pid=1752 cdq分治模版题。就是处理前缀和的时候这里变成了矩阵前缀和。我们采用扫描...

【JZOJ 3636】【BOI2012】Mobile

Description著名的手机网络运营商Totalphone 修建了若干基站收发台,以用于把信号网络覆盖一条新建的高速公路。因为Totalphone 的程序员总是很马虎的,所以,基站的传功功率不能独...

【JZOJ3623】【BOI2012】Mobile

Description著名的手机网络运营商Totalphone 修建了若干基站收发台,以用于把信号网络覆盖一条新建的高速公路。因为Totalphone 的程序员总是很马虎的,所以,基站的传功功率不能独...

1752. [BOI2007]摩基亚Mokia (cdq分治模板题)

题目:1752. [BOI2007]摩基亚Mokia cdq分治论文中的题目,通过cdq分治可以做到降维,然后用树状数组维护就可以了。 #include #include #include #in...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)