BOI 383

部署运行你感兴趣的模型镜像

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;
}


 


 

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

在字节序无关(Byte Order Independent, BOI)的上下文中,除法操作或实现通常涉及如何在不同字节序的系统之间正确处理二进制数据的解析和操作。字节序指的是多字节数据(如16位、32位或64位整数)在内存中的存储顺序。大端(Big-endian)系统将最高有效字节存储在低地址,而小端(Little-endian)系统将最低有效字节存储在低地址。 在处理除法操作时,如果涉及跨平台的数据交换或处理,必须确保数据的字节序一致,否则可能导致计算错误。BOI 通常是指在解析或处理数据时不依赖于底层系统的字节序,通常通过显式地将数据从一种字节序转换为另一种字节序来实现。 ### 除法操作中的字节序处理 当在不同字节序的系统间进行整数除法操作时,如果涉及网络传输或文件读取等场景,必须确保整数的字节序一致。例如,在网络通信中,数据通常以大端格式传输(即网络字节序),接收方在进行除法操作前需要将数据转换为本地字节序。 在 C/C++ 中,可以使用 `ntohl()` 和 `htonl()` 等函数进行 32 位整数的字节序转换: ```c #include <arpa/inet.h> uint32_t network_data = ...; // 接收到的网络字节序数据 uint32_t host_data = ntohl(network_data); // 转换为本地字节序 uint32_t result = host_data / divisor; // 进行除法操作 ``` 对于自定义的数据结构或更复杂的除法操作,可能需要手动进行字节序转换。例如,处理 64 位整数时,可以使用以下方式(假设系统支持 `bswap_64`): ```c #include <byteswap.h> uint64_t swap_endian(uint64_t value) { return bswap_64(value); } uint64_t network_data = ...; uint64_t host_data = (htonl(1) == 1) ? network_data : swap_endian(network_data); uint64_t result = host_data / divisor; ``` ### 在高级语言中的处理 在 Python 等高级语言中,字节序的处理通常通过 `struct` 模块实现。例如,解析一个大端格式的 32 位整数并进行除法操作: ```python import struct data = b'\x00\x00\x01\x00' # 大端格式的 256 value = struct.unpack('>I', data)[0] # '>I' 表示大端无符号整数 result = value / divisor ``` ### BOI 实现的注意事项 在实现 BOI 的除法操作时,需要注意以下几点: 1. **字节序一致性**:确保所有参与计算的数据在相同的字节序下进行处理,避免因字节序不一致导致的错误。 2. **跨平台兼容性**:在不同平台上进行字节序转换时,应使用标准或可移植的函数或宏,以确保兼容性。 3. **性能优化**:在频繁进行字节序转换的场景中,应考虑性能优化,例如使用内联函数或硬件支持的字节交换指令。 字节序问题在现代系统中通常由操作系统或库函数自动处理,但在底层编程、网络协议实现或跨平台数据交换中,仍需特别关注字节序的处理[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值