题目描述
<p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">Suppose that we have a square city with straight streets. A map of a city is a squar</span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">e board with n rows and n columns, each representing a street or a piece of wall.</span><span style="font-size:12.0000pt;font-family:'宋体';"></span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">A blockhouse is a small castle that has four openings through which to shoot. The </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">four openings are facing North, East, South, and West, respectively. There will be</span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';"> one machine gun shooting through each opening.</span><span style="font-size:12.0000pt;font-family:'宋体';"></span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">Powerful as the bullet is,however,it can only run across two distance and destroy </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">a blockhouse on its way.</span><span style="font-size:12.0000pt;font-family:'宋体';"> On the other hand, a wall is so strongly built that can </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">stop the bullets.</span><span style="font-size:12.0000pt;font-family:'宋体';"></span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">The goal is to place as </span><span style="font-style:italic;font-size:12.0000pt;font-family:'宋体';">many</span><span style="font-size:12.0000pt;font-family:'宋体';"> blockhouses in a city as possible so that no two can </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">destroy each other. A configuration of blockhouses is </span><span style="font-weight:bold;font-style:italic;font-size:12.0000pt;font-family:'宋体';">legal</span><span style="font-size:12.0000pt;font-family:'宋体';"> provided that no two </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">blockhouses are on the same horizontal row or vertical column in a map unless there</span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';"> is at least one wall separating them. In this problem we will consider small square</span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';"> cities (at most 4x4) that contain walls through which bullets cannot run through.</span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">The following image shows five pictures of the same board. The first picture is the </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">empty board, the second and third pictures show legal configurations, and the fourth</span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';"> and fifth pictures show illegal configurations. For this board, the maximum number</span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';"> of blockhouses in a legal configuration is 5; the second picture shows one way to </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">do it, but there are several other ways.</span><span style="font-size:12.0000pt;font-family:'宋体';"></span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">Your task is to write a program that, given a description of a map, calculates the </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">maximum number of blockhouses that can be placed in the city in a legal </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">configuration.</span><span style="font-size:12.0000pt;font-family:'宋体';"></span><span style="font-size:12.0000pt;font-family:'宋体';"></span><span style="font-size:12.0000pt;font-family:'宋体';"></span> </p>
输入格式
<p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">The input file contains one or more map descriptions, followed by a line containing</span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';"> the number 0 that signals the end of the file. Each map description begins with a</span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';"> line containing a positive integer </span><span style="font-style:italic;font-size:12.0000pt;font-family:'宋体';">n</span><span style="font-size:12.0000pt;font-family:'宋体';"> that is the size of the city; </span><span style="font-style:italic;font-size:12.0000pt;font-family:'宋体';">n</span><span style="font-size:12.0000pt;font-family:'宋体';"> will be at most </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">4. The next </span><span style="font-style:italic;font-size:12.0000pt;font-family:'宋体';">n</span><span style="font-size:12.0000pt;font-family:'宋体';"> lines each describe one row of the map, with a '.' indicating an open </span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">space and an uppercase 'X' indicating a wall. There are no spaces in the input file.</span> </p>
输出格式
<p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';">For each test case, output one line containing the maximum number of blockhouses that</span> </p> <p class="p0"> <span style="font-size:12.0000pt;font-family:'宋体';"> can be placed in the city in a legal configuration.</span><span style="font-size:12.0000pt;font-family:'宋体';"></span> </p>
样例
样例输入 1
2
XX
.X
3
.X.
X.X
.X.
3
...
.XX
.XX
0
样例输出 1
1
5
2
提交代码
请先登录后提交
🤖 AI 解题助手
DeepSeek
就绪