博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Fire Net
阅读量:4980 次
发布时间:2019-06-12

本文共 2253 字,大约阅读时间需要 7 分钟。

Description
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. 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. 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.
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.
Input
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.
Output
For each test case, output one line containing the maximum number of blockhouses that can be placed in the city in a legal configuration.
SampleInput
4.X......XX......2XX.X3.X.X.X.X.3....XX.XX4................0
SampleOutput
51524

转载于:https://www.cnblogs.com/to-creat/p/5005123.html

你可能感兴趣的文章
[置顶] Android入门教程------导入现有Android工程
查看>>
《Entity Framework 6 Recipes》中文翻译系列 (40) ------ 第七章 使用对象服务之从跟踪器中获取实体与从命令行生成模型(想解决EF第一次查询慢的,请阅读)...
查看>>
Intro to Filtering with Network Monitor 3.0
查看>>
问卷调查
查看>>
Contest Record
查看>>
51Nod 1066 - Bash游戏
查看>>
oracle控制何时触发审计动作
查看>>
NVelocity用法
查看>>
关于xp_cmdshall开启特定账号执行的相关设置步骤
查看>>
[USACO 6.3.2] Cryptcowgraphy
查看>>
.net 开发人员面试题 - 多线程
查看>>
PHP实现的快速排序
查看>>
Dave Python 练习十七 -- 正则表达式
查看>>
混沌开窍---24幅由算法生成的正方形图像
查看>>
java中newInstance和new(转)
查看>>
面向对象技术
查看>>
centos7 Linux 安装mysql
查看>>
dom的综合练习
查看>>
python中sort方法
查看>>
python字符串
查看>>