2285. Lights Off

单点时限: 2.0 sec

内存限制: 256 MB

Since we all rely on mother earth, it’s our duty to save her. Therefore, you’re now asked to save energy by switching lights off.

Problem

A friend of yours has the following problem in his job. There’s a grid of size 10x10, where each square has a light bulb and a light switch attached to it. Unfortunately, these lights don’t work as they are supposed to. Whenever a switch is pressed, not only it’s own bulb is switched, but also the ones left, right, above and under it. Of course if a bulb is on the edge of the grid, there are less bulbs switched.

When a light switches it means it’s now on if it was off before and it’s now off if it was on before. Look at the following examples, which show only a small part of the whole grid. They show what happens if the middle switch is pressed. “O” stands for a light that’s on, “#” stands for a light that’s off.

    ###      #O#

###  ->  OOO

###      #O#

###      #O#

OOO  ->  ###

###      #O#

Your friend loves to save energy and asks you to write a program that finds out how many times he has to press switches in order to turn all the lights off.

输入格式

There are several testcases in the input. Each testcase is preceded by a single word that gives a name for the testcase. After that name there follow 10 lines, each of which contains a 10-letter string consisting of “#” and “O”. The end of the input is reached when the name string is “end”.

输出格式

For every testcase, print one line that consists of the testcase name, a single space character and the minimum number of times your friend has to press a switch. It is guaranteed that you can switch off all the light bulbs in each test case.

样例

Input
all_off
##########
##########
##########
##########
##########
##########
##########
##########
##########
##########
all_on
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
simple
#O########
OOO#######
#O########
####OO####
###O##O###
####OO####
##########
########O#
#######OOO
########O#
end
Output
all_off 0
all_on 44
simple 4

4 人解决,8 人已尝试。

4 份提交通过,共有 11 份提交。

8.0 EMB 奖励。

创建: 15 年,9 月前.

修改: 6 年,8 月前.

最后提交: 9 年,11 月前.

来源: Freshman Programming Contest

题目标签