QOJ.ac

QOJ

时间限制: 4 s 内存限制: 1024 MB 总分: 22

#5772. 末日将至

统计

糟糕!世界脆弱的政治平衡终于崩溃了,每个人都向其他人宣战。你曾警告过所有愿意听的人这种情况会发生,但他们注意了吗?哈!现在你唯一能做的就是尽可能长久地生存下去。

幸运的是(某种程度上),每个国家的工业中心都已经被核平了,所以每个国家唯一可用的攻击方式就是向彼此派遣一波又一波的征召兵。这限制了每个国家只能攻击其直接邻国。世界是一个 $R \times C$ 的网格,行号从最北端的 $1$ 到最南端的 $R$,列号从最西端的 $1$ 到最东端的 $C$。每个国家占据网格中的一个方格,这意味着每个国家最多可以到达 $4$ 个相邻的国家。

每个国家开始时都有一个众所周知的特定力量值。他们没有任何先进战略的概念,因此在每天开始时,他们只会选择力量最强的邻国(若力量相同,则优先选择最北端的国家,若仍相同,则选择最西端的国家)并用军队进行攻击。军队的力量等于该国当前的力量 $S$;到当天结束时,它将消耗掉该邻国 $S$ 的力量。力量降至 $0$ 的国家即被摧毁。请注意,所有国家都在同一时间进行攻击;无论一个国家当天是否受到攻击,其军队的力量都是一样的。

你的国家位于 $(c, r)$,即第 $r$ 行第 $c$ 列。幸运的是,你的国家听从了你的建议,所以你不必遵循这种疯狂的策略。你可以选择在某一天攻击你的任何邻国(或者什么都不做)。但是,你不能同时攻击多个邻国,也不能以低于全额力量的军队进行攻击。

确定你能生存的最大天数。

样例

输入格式 1

2
3 3 2 2
2 3 2
1 7 1
2 1 2
4 3 2 1
1 2 2 0
10 8 5 10
10 2 9 10

输出格式 1

Case #1: forever
Case #2: 3 day(s)

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.