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...

[BOI2007]摩基亚Mokia (cdq分治)

摩尔瓦多的移动电话公司摩基亚(Mokia)设计出了一种新的用户定位系统。和其他的定位系统一样,它能够迅速回答任何形如“用户C的位置在哪?”的问题,精确到毫米。但其真正高科技之处在于,它能够回答形如“给...

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

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

JZOJ 【BOI2012】Peaks

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

cogs 1752. [BOI2007]摩基亚Mokia

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

【JZOJ 3636】【BOI2012】Mobile

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

【JZOJ3623】【BOI2012】Mobile

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

FT383NT电源管理

  • 2014年06月22日 10:47
  • 264KB
  • 下载

[CF383]一个迟来的检讨

这场比赛是亚洲区比赛回来之后打得比较正经的一次个人赛,同时也暴露出了我最近精力及其的不集中,做事情非常的没有条理。非常的没有耐心,需要冷静下来。...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:BOI 383
举报原因:
原因补充:

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