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

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

Fire Net

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

Total Submission(s): 10462    Accepted Submission(s): 6154

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

 

//题意是一个地图,要在城市放尽可能多的碉堡,但是碉堡不能在同一行,或者同一列,在同一行必须有个坚固的墙

问最多可以放多少碉堡

//简单的DFS的应用,代码里写的很详细了。。

1 #include 
2 #include
3 #include
4 using namespace std; 5 6 char mp[4][4]; 7 int vis[4][4]; 8 int n; 9 int ans; 10 11 void fang(int x,int y)//放下 12 { 13 vis[x][y]=1; 14 int i; 15 i=x; 16 while (i+1
=0&&mp[i-1][y]=='.') 23 { 24 i--; 25 vis[i][y]++; 26 } 27 i=y; 28 while (i+1
=0&&mp[x][i-1]=='.') 35 { 36 i--; 37 vis[x][i]++; 38 } 39 } 40 41 void che(int x,int y)//撤走 42 { 43 vis[x][y]=0; 44 int i; 45 i=x; 46 while (i+1
=0&&mp[i-1][y]=='.') 53 { 54 i--; 55 vis[i][y]--; 56 } 57 i=y; 58 while (i+1
=0&&mp[x][i-1]=='.') 65 { 66 i--; 67 vis[x][i]--; 68 } 69 } 70 71 int dfs(int l,int cnt)//去l行放置 72 { 73 if (cnt>ans) 74 { 75 ans=cnt; 76 } 77 if (l>=n) return 0; //出界 78 79 int i; 80 for (i=0;i
>n&&n) 96 { 97 getchar(); 98 int i,j; 99 for (i=0;i
>mp[i][j];103 getchar();104 }105 ans=0;106 memset(vis,0,sizeof(vis));107 dfs(0,0); //从第0行开始放,放置的个数初始值为 0108 cout<
<
View Code

 

转载于:https://www.cnblogs.com/haoabcd2010/p/5964922.html

你可能感兴趣的文章
excel定义函数操作文档
查看>>
安装nginx1.8
查看>>
nginx 基础配置和常用模块
查看>>
canvas绘制时钟
查看>>
oracle更改控制文件位置
查看>>
apache配置网络驱动器
查看>>
awk 学习笔记
查看>>
小型企业网站的架构 & 安全配置与防护
查看>>
UVA 1376 Animal Run 最短路
查看>>
mysql模糊查询的优化方法--亲自实践
查看>>
Exchange Server 2013 规划系列之日志容量规划、数据库容量规划
查看>>
职场必读的经典励志故事
查看>>
九爷带你了解 nginx 日志配置指令详解
查看>>
Jenkins 自动化部署上线
查看>>
unittest框架执行用例
查看>>
广州限购后首场车展明日开幕
查看>>
简述ssl协议及利用openssl创建私有CA
查看>>
那些年php编程犯过的错(1) -- 字符串相等
查看>>
React Native——react-navigation的使用
查看>>
“二子乘舟”的故事很难讲
查看>>