QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22337. 農場危機

Statistics

Farmer John 與他奇特的舞蹈牛群正排練新音樂劇《慾望號街牛》。排練中某時,乳牛疊成 $N$ $(1 \le N \le 1,000)$ 組,每組 30 頭,一頭站在另一頭背上(真是神奇的牛)。牧場上除了這些牛堆,另有位於不同位置的 $M$ $(1 \le M \le 1,000)$ 個草堆。下圖是可能的布局,C 表示 30 頭牛的堆,H 表示草堆:

                8 .........
                7 ....CH.H.         C = stack of 30 cows
                6 .........
                5 .........         H = haystack
                4 ..C.HH...
                3 .........
                2 .....C.HH
                1 .........
                  123456789

作為音樂劇指揮,Farmer John 有四種音調的哨子,分別命令每堆最底下的牛連同其上的所有牛向北、南、東或西移動一個單位。

每當牛堆進入有草堆的格點,最頂上的牛(即使只剩一頭)就跳上草堆,其餘牛移到草堆所在位置。因此,底下的牛遇到 30 次草堆(可不同,也可重複)後,30 頭全落在草堆上,或草堆上的牛背上,原牛堆便耗盡。堅固的每個草堆可以支撐無限頭牛。

Farmer John 朝牧場另一側 Farmer Don 的擠奶設施看去,驚恐地發現巨大奶罐爆炸,牛奶巨浪衝向表演中的牛!草堆上的牛安全,因此他必須把原本簡單的舞蹈變成救命技法,盡量救更多牛。

給定浪潮到達前可吹哨次數 $K$ $(1 \le K \le 30)$,以及 $N$ 堆牛、$M$ 個草堆的座標 $X_{i}$、$Y_{i}$ $(1 \le X_{i} \le 1,000; 1 \le Y_{i} \le 1,000)$(草堆目前均無牛),求最多能救的牛數及對應吹哨序列。以 E、N、W、S 分別表示東、北、西、南;最優序列中取字典序最小的。輸入中牛堆與草堆的初始位置不重合。

牛可以移到任意位置,包括牧場外。

輸入格式

  • 第 1 行:空格分隔的三個整數 $N$、$M$ 和 $K$。
  • 第 $2,\ldots,N+1$ 行:第 $i+1$ 行以兩個空格分隔的整數 $X_{i}$ 和 $Y_{i}$ 描述一堆 30 頭牛的 $X$、$Y$ 座標。
  • 第 $N+2,\ldots,N+M+1$ 行:第 $i+N+1$ 行以兩個空格分隔的整數 $X_{i}$ 和 $Y_{i}$ 描述草堆的 $X$、$Y$ 座標。

輸出格式

  • 第 1 行:一個整數,最多可救的牛數。
  • 第 2 行:$K$ 個字元,救牛數最多且字典序最小的命令序列。

範例

輸入格式 1

3 6 3
3 4
6 2
5 7
8 2
9 2
6 4
5 4
6 7
8 7

輸出格式 1

6
EEE

說明

吹三次向東的哨子,隨後牛奶淹沒牧場。每個草堆最終救下一頭牛。

題目作者:Thomas Williamson,2004

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.