编程介的小学生 2017-03-21 13:11 采纳率: 20.5%
浏览 808
已采纳

FatMouse and JavaBean

FatMouse is lucky enough to find a map of another storehouse which contains his favorite food, JavaBean. The map shows a rectangular house with several square rooms, each either stores some JavaBeans or rests some cats. Each room has at most one door in and at most one door out. Each door opens toward one direction only, that is, room A has a door open toward room B means that one can pass from A to B, but not the other way around (and B can only be reached from A unless FatMouse digs in directly). After some negotiations those cats agree that they can let FatMouse pass if he pays them one JavaBean each. FatMouse can dig into the house and dig out at any point. Now he comes to you with his map, asking if you could tell him where to dig in and where to dig out in order to get the maximum amount of JavaBeans.

Input

Input consists of several test cases.

For each test case, the first line contains 2 positive integers M and N which are the row and column sizes of the house.

Then M lines follow, each contains N pairs of bean_num and door_dir which describe the rooms in the house. The bean_num is the number of JavaBeans stored, or the negative number of cats in that room. The door_dir is a character which represents the door direction of the room where 'E' for east, 'S' for south, 'W' for west, 'N' for north, and 'X' for no door (that is, FatMouse might be able to enter this room from its neighboring rooms, but can only leave this room by digging a hole out).

All the integers in input have their absolute value no more than 500.

Output

For each test case, print in one line the maximum amount of JavaBeans FatMouse can possibly take, followed by two pairs of numbers (x1, y1) and (x2, y2) which are the digging in and out positions, respectively. If there is no way for him to get any JavaBeans at all, print the message "Forget it."

The upper-left corner of the house is (1,1) and the lower-right corner is (M, N).

Please refer to the samples for output format.

Sample Input

1 3
3 E -2 E 3 X
1 1
-1 X

Sample Output

4 (1,1) (1,3)
Forget it.

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-03-29 15:06
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退