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

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

Fire Net

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5215    Accepted Submission(s): 2935


Problem 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.
 

 

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
 

 

Source
 

 

Recommend
We have carefully selected several similar problems for you:            
 
1 //0MS    228K    2037 B    C++     2 //建图+二分  3 #include
4 #include
5 char c[10][10],mapc[10][10],mapr[10][10]; 6 int g[10][10]; 7 int vis[10]; 8 int match[10]; 9 int n,N,M;10 void build() //建图 11 {12 memset(mapc,0,sizeof(mapc));13 memset(mapr,0,sizeof(mapr));14 memset(g,0,sizeof(g));15 N=M=0;16 for(int i=0;i
N) N=cnt;28 j++;29 }30 } 31 cnt=0;32 for(int j=0;j
M) M=cnt;39 i++;40 }41 } 42 for(int i=0;i

 

转载于:https://www.cnblogs.com/GO-NO-1/articles/3389480.html

你可能感兴趣的文章
学会这二十个正则表达式,能让你少些1000行代码!
查看>>
关于Cocos Creator脚本执行顺序的几点补充
查看>>
Powershell-Exchange:设置分层通讯薄中通讯组的优先级
查看>>
开启好用的Lync联系人即时模糊搜索功能
查看>>
Microsoft Hyper-V Server 2012开启虚拟化-SMB 3.0
查看>>
Powershell管理系列(十二)Exchange新启用的邮箱禁用OWA及Activesync的访问
查看>>
Windows 8上安装本地回环网卡
查看>>
Exchange Server 2013系列十二:邮箱的基本管理
查看>>
[C#进阶系列]专题二:你知道Dictionary查找速度为什么快吗?
查看>>
并发连接数、请求数、并发用户数
查看>>
SDA报告给各国网络空间安全防卫水平进行评级
查看>>
去小机化思维(二)--【软件和信息服务】2015.03
查看>>
【翻译】Sencha Cmd中脚本压缩方法之比较
查看>>
最新.NET 5.0 C#6 MVC6 WCF5 NoSQL Azure开发120课视频
查看>>
爱因斯坦计划最新进展(201710)
查看>>
传统HA系统的终结者-【软件和信息服务】2013.11
查看>>
Spread for Windows Forms快速入门(15)---使用 Spread 设计器
查看>>
自动抓屏工具 -- psr
查看>>
jqPlot
查看>>
将Access换成sql要改些什么?注意哪些问题?(汇总)
查看>>