博客
关于我
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/

你可能感兴趣的文章
算法入门
查看>>
cf-A. Wet Shark and Odd and Even(水)
查看>>
How many ways(记忆化搜索)
查看>>
Train Problem II(卡特兰数+大数乘除)
查看>>
Ignatius and the Princess II(全排列)
查看>>
一些技术博客
查看>>
技术分享 | MySQL 8.0:字符集从 utf8 转换成 utf8mb4
查看>>
第01问:MySQL 一次 insert 刷几次盘?
查看>>
分布式 | DBLE 3.20.07.0 来啦!
查看>>
分布式 | Prepare Statement 协议游标可行性
查看>>
技术分享 | mysqlsh 命令行模式 & 密码保存
查看>>
智能在线考试系统
查看>>
2021-05-15 C语言中的 getchar()和 putchar()
查看>>
远程控制安卓终端步骤笔记
查看>>
ADS封装
查看>>
混频器与变频器在射频通信中的区别
查看>>
合成孔径雷达之聚束式合成孔径雷达
查看>>
频率与大气衰减
查看>>
振荡器指标
查看>>
单片机之晶振
查看>>