Fire Net

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5175    Accepted Submission(s): 2908

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

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxn 10
char maze[maxn][maxn];
int ans,n,count,max;
/*用p作为人的标记*/
/*判断竖横是否有城堡*/
bool judge(int x,int y)
{
int i;
bool flag=true;
for(i=y+;i<=n;i++)
{
if(maze[x][i]=='P')
{
flag=false;
break;
}
else
if(maze[x][i]=='X')
break;
}
if(!flag)
return false;
for(i=y-;i>=;i--)
{
if(maze[x][i]=='P')
{
flag=false;
break;
}
else
if(maze[x][i]=='X')
break;
}
if(!flag)
return false;
for(i=x+;i<=n;i++)
{
if(maze[i][y]=='P')
{
flag=false;
break;
}
else if(maze[i][y]=='X')
break;
}
if(!flag)
return false;
for(i=x-;i>=;i--)
{
if(maze[i][y]=='P')
{
flag=false;
break;
}
else if(maze[i][y]=='X')
break;
}
if(!flag)
return false;
else
return true;
}
void dfs()
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(maze[i][j]=='.'&&true==judge(i,j))
{
count++;
maze[i][j]='P';
dfs();
if(count>ans)
ans=count;
maze[i][j]='.';
count--;
}
}
}
}
int main()
{
int i,j;
while(scanf("%d",&n),n)
{
getchar();
max=;
for( i=;i<=n;i++)
{
for( j=;j<=n;j++)
{
scanf("%c",&maze[i][j]);
}
getchar();
}
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(maze[i][j]!='X')
{
count=;
ans=;
maze[i][j]='P';
dfs();
maze[i][j]='.';
if(ans==) max=;
else
if(ans>max) max=ans;
}
}
}
printf("%d\n",max);
}
return ;
}

思路:   每次涂一个点,然后生成一张图,将其作为一张新图,又重新开始涂点.....周而复始.....

并不断记录点的最大个数.用栈,或者回溯都可以实现.....

HDUOJ---------(1045)Fire Net的更多相关文章

  1. DFS ZOJ 1002/HDOJ 1045 Fire Net

    题目传送门 /* 题意:在一个矩阵里放炮台,满足行列最多只有一个炮台,除非有墙(X)相隔,问最多能放多少个炮台 搜索(DFS):数据小,4 * 4可以用DFS,从(0,0)开始出发,往(n-1,n-1 ...

  2. hdu 1045 Fire Net(最小覆盖点+构图(缩点))

    http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS     Memory Limit:32768KB   ...

  3. HDOJ(HDU).1045 Fire Net (DFS)

    HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...

  4. HDU 1045 Fire Net 【连通块的压缩 二分图匹配】

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)    ...

  5. HDU 1045 Fire Net(dfs,跟8皇后问题很相似)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)   ...

  6. HDU 1045 Fire Net 状压暴力

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)  ...

  7. HDU 1045(Fire Net)题解

    以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] 给定大小的棋盘中部分格子存在可以阻止互相攻击的墙,问棋盘中可以放置最多多少个可以横纵攻击炮塔. [题目分析] 这题本来在搜索专题 ...

  8. HDU 1045——Fire Net——————【最大匹配、构图、邻接矩阵做法】

    Fire Net Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  9. hdu 1045:Fire Net(DFS经典题)

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  10. hdoj 1045 Fire Net

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

随机推荐

  1. 进程外Session保存和全局文件错误捕获

    Session深入学习,进程外的Session 当用户登入页面跳转时候,我们会将用户登录信息保存在服务端一个键值对的Session(Session池)中.那么Session池又是在哪里呢? 它最终默认 ...

  2. easyui-datetimebox设置默认时分秒00:00:00

    datetimebox默认打开面板显示的是当前的时间,有个需求就是当打开面板时显示固定的”00:00:00”时间, 它本身有个方法spinner方法可以获得时间微调器对象,它所依赖的组件combo有个 ...

  3. [转载] java的书

    1. Java 语言基础 谈到Java 语言基础学习的书籍,大家肯定会推荐Bruce Eckel 的<Thinking in Java >.它是一本写的相当深刻的技术书籍,Java 语言基 ...

  4. 上下变换中 aspect的选择

    在电视制作还没有完全整转到高清之前,有很多原来的SD素材需要转到HD信号进入高清切换或者编辑平台,电视台是电视节目的发射源端 ,所以上变换过程不能引入额外的噪声或者失真: 上变换使用的方式一般有4种: ...

  5. 两个JS对象怎样才能相等

    在JS中,两个对象如何才能相等?下面的两个 Alert,只有一个输出true.  在JS中如何才能构造出两个JS对象相等? var prop1 = {asd:{def:'abc'}}; var pro ...

  6. C#(64位系统) 解决"未能加载文件或程序集,或它的某一个依赖项..."

    这个问题通常出在引用第三方DLL或者自己以前写的DLL. 在64位系统下则可能会出现这种问题. 今天下载MySQLDriverCS后引用遍出现了这个问题,参考了一些文档,下面给出解决方法: 将项目的生 ...

  7. IOS 实现界面本地化(国际化)

    在制作应用程序的时候,可以使用本地化功能,将应用程序的内容翻译成多种语言,在不同的区域显示不同的语言.下面就通过简体中文本地化设置来讲解一下本地化的简单使用. 一.让应用程序支持中文语言环境 选择需要 ...

  8. IIS7.5配置Asp.net项目出现HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。

    近日在将一个Asp.net项目部署到IIS7.5上时却出现了HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理. 因为IIS里面使用的都是默 ...

  9. Ensemble_learning 集成学习算法 stacking 算法

    原文:https://herbertmj.wikispaces.com/stacking%E7%AE%97%E6%B3%95 stacked 产生方法是一种截然不同的组合多个模型的方法,它讲的是组合学 ...

  10. 给MySQL增加一个表示例

    仅为记录用,图样图升破,看客速退散. create table logtable(   id int(20) PRIMARY KEY AUTO_INCREMENT,   concept varchar ...