ZOJ1002

Fire Net

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.

假设我们有一个正方形的城市,并且街道是直的。城市的地图是n行n列,每一个单元代表一个街道或者一块墙。

A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing North, East, South, and West, respectively. There will be one machine gun shooting through each opening.

碉堡是一个小城堡,有四个开放的射击口。四个方向是面向北、东、南和西。在每一个口子上有一架机关枪。

Here we assume that a bullet is so powerful that it can run across any distance and destroy a blockhouse on its way. On the other hand, a wall is so strongly built that can stop the bullets.

假设子弹能够穿过任何距离,并且摧毁路上的碉堡。另一方面,子弹不能穿越墙。

The goal is to place as many blockhouses in a city as possible so that no two can destroy each other. A configuration of blockhouses is legal provided that no two blockhouses are on the same horizontal row or vertical column in a map unless there is at least one wall separating them. In this problem we will consider small square cities (at most 4x4) that contain walls through which bullets cannot run through.

我们的目标是在城市里设置足够多的碉堡,并且任何两个碉堡都不会互相摧毁。正确的配置是没有两个碉堡在相同的水平行或者垂直列上,除非碉堡之间有墙把它们分开。在这个问题中,我们将使用小的方形城市(最多4*4),它包含了墙,并且子弹不能穿越。

The following image shows five pictures of the same board. The first picture is the empty board, the second and third pictures show legal configurations, and the fourth and fifth pictures show illegal configurations. For this board, the maximum number of blockhouses in a legal configuration is 5; the second picture shows one way to do it, but there are several other ways.

接下来的图片显示五张城市地图,第1张图片是空的布局,第2张和第3张图片显示了合法的配置,第4和第5张图片显示了非法的配置。对于这样的地形来说,碉堡的最大数是5;第2张图片显示了这个配置方案,但还有其他的配置方案。

Your task is to write a program that, given a description of a map, calculates the maximum number of blockhouses that can be placed in the city in a legal configuration.

你的任务是写一个程序,在给出的地图描述下,计算城市中可以合法放置的碉堡的最大数。

The input file contains one or more map descriptions, followed by a line containing the number 0 that signals the end of the file. Each map description begins with a line containing a positive integer n that is the size of the city; n will be at most 4. The next n lines each describe one row of the map, with a '.' indicating an open space and an uppercase 'X' indicating a wall. There are no spaces in the input file.

输入文件包含一个或者多个地图描述,0作为文件的结束。每个地图描述首行是城市的尺寸n,n最大为4。接下来的n行描述了地图的每一行,符号“."代表开放区域,大写的X代表墙。输入文件中没有空格。

For each test case, output one line containing the maximum number of blockhouses that can be placed in the city in a legal configuration.

每一个测试用例,最后输出一行为合法放置碉堡的最大数。

Sample input:

4
.X..
....
XX..
....
2
XX
.X
3
.X.
X.X
.X.
3
...
.XX
.XX
4
....
....
....
....
0

Sample output:

5
1
5
2
4
posted @ 2017-03-08 18:49  RunningYY  阅读(709)  评论(3编辑  收藏  举报