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 ...
随机推荐
- Javascript时间以及格式化秒
var now = new Date(); timer = $.timer(timeout, function () { var sec_num = Math.ceil((now.getTim ...
- Flask 学习(四)静态文件
Flask 学习(四)静态文件 动态 web 应用也需要静态文件,一般是 CSS 和 JavaScript 文件.理想情况下你的服务器已经配置好提供静态文件的服务. 在开发过程中, Flask 也能做 ...
- 【BZOJ】【4052】【CERC2013】Magical GCD
DP/GCD 然而蒟蒻并不会做…… Orz @lct1999神犇 首先我们肯定是要枚举下端点的……嗯就枚举右端点吧…… 那么对于不同的GCD,对应的左端点最多有log(a[i])个:因为每次gcd缩小 ...
- 【WCF】HTTP 无法注册 URL 进程,不具有此命名空间的访问权限
背景 如题,在运行WCF宿主主机时,出现了问题. 捕获异常为:HTTP 无法注册 URL http://+:8000/WCF/.进程不具有此命名空间的访问权限(有关详细信息,请参见 http: ...
- 深入理解VUE样式style层次分析
刚开始使用vue的时候容易被里面的样式搞懵: 样式可以在main.js中引入,在模块js文件中引入,在组件中的style标签引入,在组件中的script标签引入,还可以在index.html的body ...
- 机器学习的开源平台 TensorFlow
一. google第二代人工智能机器学习开源工具. http://www.tensorfly.cn/ 二. 知乎上关于机器学习的资料问答 https://www.zhihu.com/question/ ...
- 数据需求统计常用awk命令
原文:http://www.5iops.com/html/2013/script_0418/267.html 1.将时间转换为时间戳 select unix_timestamp('2009-10-26 ...
- Java 抽象类和接口有什么差别
抽象类和接口有什么差别? 1. 抽象类在java语言中所表示的是一种继承关系,一个子类仅仅能继承一个父类.可是能够实现多个接口. 2. 在抽象类中能够拥有自己的成员变量和非抽象类方法,可是接口中仅仅能 ...
- 将浮点数保持几位小数,尾数舍入的Format函数
select format(hours,2) from pos.daywork
- Linux之nohup命令:实现退出终端后程序继续后台运行
转自:http://tech.ccidnet.com/art/302/20070618/1115599_1.html 简单而有用的nohup命令在UNIX/LINUX中,普通进程用&符号放到后 ...