#P2905. [USACO08OPEN] Crisis on the Farm G

[USACO08OPEN] Crisis on the Farm G

题目描述

约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练。奶牛们分成一堆一堆,共 10001000)堆。每一堆里,3030 只奶牛一只踩在另一只的背上,叠成一座牛塔。牧场 里还有 M(1<M<1000)M(1 < M < 1000) 个高高的草垛。

作为出色的指挥家,约翰可以通过口哨指挥奶牛们移动。他的口哨有四个音,分别能使所有的牛塔向东南西北四个方向移动一格。

每一次,当一个牛塔到达了一个草垛所在的格子,牛塔最上方的奶牛就会跳到草垛上,而且不再下来,而其他奶牛仍然呈塔状站在草垛所在的格子里.当牛塔只剩一只奶牛时,这只奶牛也会跳到草垛上。

突然,约翰大惊失色:原来邻家的奶缸爆炸了!滚滚而下的牛奶正朝着约翰的牧场冲来,不久就要将牧场淹没。约翰必须马上行动,用口哨声挽救奶牛们的生命。他要指挥奶牛尽量多地跳上草操,草操上的奶牛将不会被淹死.

约翰还有 KK 次吹口哨的机会.那他最多还能救多少奶牛呢?请计算最多能挽救的奶牛数,以及达到这个数目约翰需要吹的口哨调子序列。序列用 E,W,S,N\mathtt{E,W,S,N} 表示东西南北。如果有多种序列能达到 要求,输出作为字符串最小的。

输入格式

* Line 1: Three space-separated integers: N, M, and K

* Lines 2..N+1: Line i+1 describes the X,Y location of a stack of 30 cows using two space-separated integers: X_i and Y_i

* Lines N+2..N+M+1: Line i+N+1 describes the X,Y location of a haystack using two space-separated integers: X_i and Y_i

输出格式

* Line 1: A single integer that is the most number of cows that can be saved.

* Line 2: K characters, the lexicographically least sequence of commands FJ should issue to maximize the number of cows saved.

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

6 
EEE 

提示

Use the 'east' whistle three times, at which point the milk floods the area. Each haystack ends up saving 1 cow.

对于 100%100\% 的数据,1K301\le K\le 301N,M,Xi,Yi10001\le N,M,X_i,Y_i\le 1000