QOJ.ac

QOJ

时间限制: 3 s 内存限制: 256 MB 总分: 100

#1076. 洪水泛滥的田野

统计

Farmer John 遇到了一个难题:天在下雨,他的牧场面临洪水威胁。幸运的是,他投资了一套最先进的排水系统,确保整个农场的水位保持一致。但他对地形的运气就没那么好了。Farmer John 的奶牛只能站在干燥的土地上:如果土地变湿,任何处于该位置的奶牛都会淹死。幸运的是,奶牛每小时可以移动到一个相邻的网格扇区,这让它们有机会躲避洪水(水位每小时都会涨落)。

Farmer John 将他的田地划分成了网格扇区,并用行和列进行索引。每个网格扇区都很小,只能容纳一头奶牛。

给定 Farmer John 田地的描述、奶牛的起始位置以及每小时的水位高度,假设 Farmer John 的奶牛极其聪明且具有预见性,因此总是能做出最优移动,问 Farmer John 最多有多少头奶牛可以存活?

输入格式

输入包含多个测试用例。每个测试用例的第一行包含三个整数 $n$ ($1 \le n \le 100$),$k$ ($0 \le k \le 100$) 和 $h$ ($1 \le h \le 24$),其中 $n$ 表示 Farmer John 田地的大小(为 $n \times n$ 的网格扇区),$k$ 是田地中奶牛的数量,$h$ 是需要追踪的小时数。

接下来的 $n$ 行,每行包含 $n$ 个整数,表示 Farmer John 田地中每个网格扇区的高度 ($0 \le \text{height} \le 100$)。输入中的第一行为第 $0$ 行,最后一行为第 $n-1$ 行。每行的第一列为第 $0$ 列,最后一列为第 $n-1$ 列。

随后的 $k$ 行,每行包含一对整数 $r$ 和 $c$ ($0 \le r, c < n$)。每一行表示一头奶牛在第 $0$ 小时的网格扇区位置,其中 $r$ 为行,$c$ 为列。没有两头奶牛会处于同一位置。

接下来的 $h$ 行,每行包含一个整数,表示该小时的洪水水位 ($0 \le \text{level} \le 100$)。这些行按顺序给出:先是第 $1$ 小时,然后是第 $2$ 小时,依此类推。注意,时间从第 $1$ 小时开始,而奶牛的位置是在第 $0$ 小时给出的,因此奶牛在第一次洪水到来之前有机会移动。如果一个网格方块的高度 $\le$ 给定小时的洪水水位,则该网格被视为被淹没。

输入以一行三个 $0$ 结束。

输出格式

对于每个测试用例,输出一个整数,表示存活奶牛的最大可能数量。不要输出任何空格,也不要在答案之间打印任何空行。

样例

输入 1

3 1 3
2 1 2
3 1 3
2 4 2
1 1
0
2 
1
0 0 0

输出 1

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.