博客
关于我
Fire Net(dfs)
阅读量:613 次
发布时间:2019-03-13

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

Fire Net

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

Total Submission(s): 7944    Accepted Submission(s): 4534

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
 题解:
二维数组的坐标用一个数字表示,这个点从0到n*n每次选或不选,加一个判断;
代码:
 
1 #include
2 #include
3 #define MAX(x,y) x>y?x:y 4 const int INF=-0xfffffff; 5 char map[5][5]; 6 int n,maxnum; 7 bool judge(int t){ 8 int w,h,p,q; 9 h=t/n;w=t%n;10 p=h;q=w;11 while(h>=0){12 if(map[h][w]=='@')return false;13 if(map[h][w]=='X')break;14 h--;15 }16 w=q;h=p;17 while(w>=0){18 if(map[h][w]=='@')return false;19 if(map[h][w]=='X')break;20 w--;21 }22 w=q;h=p;23 while(w

 

转载地址:http://cehaz.baihongyu.com/

你可能感兴趣的文章
go语言中类的继承和方法的使用
查看>>
VSCode插件(一)—— Git Graph和GitLens
查看>>
C# 合并和拆分PDF文件
查看>>
python第一课
查看>>
caffe运行mnist例子时候出现的一些问题
查看>>
Ubuntu 修改权限的操作
查看>>
caffe训练的时候遇到的text-format 错误解决方案。
查看>>
Java 8新特性(一):Lambda表达式
查看>>
hibernate -- HQL语句总结
查看>>
把JSP放到WEB-INF后以保护JSP源代码
查看>>
ZOJ问题(坑死了)
查看>>
Fire Net(dfs)
查看>>
Little Zu Chongzhi's Triangles
查看>>
Oh, my goddess(bfs)
查看>>
算法入门
查看>>
cf-A. Wet Shark and Odd and Even(水)
查看>>
How many ways(记忆化搜索)
查看>>
Train Problem II(卡特兰数+大数乘除)
查看>>
Ignatius and the Princess II(全排列)
查看>>
又一道简单题&&Ladygod(两道思维水题)
查看>>