HDUOJ---------(1045)Fire Net
Fire Net
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5175 Accepted Submission(s): 2908
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.
#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的更多相关文章
- DFS ZOJ 1002/HDOJ 1045 Fire Net
题目传送门 /* 题意:在一个矩阵里放炮台,满足行列最多只有一个炮台,除非有墙(X)相隔,问最多能放多少个炮台 搜索(DFS):数据小,4 * 4可以用DFS,从(0,0)开始出发,往(n-1,n-1 ...
- hdu 1045 Fire Net(最小覆盖点+构图(缩点))
http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS Memory Limit:32768KB ...
- HDOJ(HDU).1045 Fire Net (DFS)
HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...
- HDU 1045 Fire Net 【连通块的压缩 二分图匹配】
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1045 Fire Net(dfs,跟8皇后问题很相似)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1045 Fire Net 状压暴力
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1045(Fire Net)题解
以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] 给定大小的棋盘中部分格子存在可以阻止互相攻击的墙,问棋盘中可以放置最多多少个可以横纵攻击炮塔. [题目分析] 这题本来在搜索专题 ...
- HDU 1045——Fire Net——————【最大匹配、构图、邻接矩阵做法】
Fire Net Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- hdu 1045:Fire Net(DFS经典题)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- hdoj 1045 Fire Net
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
随机推荐
- EasyUI 常规用法
(function () { // 获取树的路径,如 组织分类 > YHBH > 湖南省卫生厅 > 湖南省长沙市 var getBreadcrumbs = funct ...
- Informatica 常用组件Lookup之十 创建查找转换
在 Mapping Designer 中选择"转换-创建".选择查找转换.输入转换名称.查找转换的命名惯例是 LKP_TransformationName.单击"确定&q ...
- Win Socket编程原理及简单实例
[转]http://www.cnblogs.com/tornadomeet/archive/2012/04/11/2442140.html 使用Linux Socket做了小型的分布式,如Linux ...
- QtWebKit
WekKit官网:http://www.webkit.org/ QtWebKit官网及安装:http://trac.webkit.org/wiki/QtWebKit#GettingInvolved Q ...
- Cesium随笔(2)加载天地图地图服务【转】
Cesium自带的图层是bing地图和esri,mapbox等图层,木有中文注记,想加载中文注记的图层?废话不说,上代码: var viewer = new Cesium.Viewer('cesium ...
- SQL查询今天、昨天、7天内、30天【转】
SQL查询今天.昨天.7天内.30天 今天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=0 昨天的所有数据:sele ...
- jQuery多媒体播放器插件jQuery Media Plugin使用方法
jQuery Media Plugin是一款基于jQuery的网页媒体播放器插件,它支持大部分的网络多媒体播放器和多媒体格式,比如:Flash, Windows Media Player, Real ...
- 简单使用CSS3实现炫酷读者墙效果
读者墙,在很多网站上都有,没有遇到过的,可以参考度娘:读者墙http://www.baidu.com/s?wd=%B6%C1%D5%DF%C7%BD 使用基础的Html和CSS写出雏形 需要一提的是头 ...
- iphone之使用讯飞语音sdk实现语音识别功能
1.首先下载讯飞sdk及文档:http://open.voicecloud.cn/ 2.学习里面的demo简单实现了一个小的语音识别功能 先做一个简单demo,看看识别效果.注:语音识别必须联网. 所 ...
- IIS-将iis直接指向.net代码会出现错误
这是由于没有bin文件导致的,将bin文件加上之后就可以了.