zoj 1002 Fire Net(不能位于同行或同列,问最多放几个)

ZOJ1002题——Fire Net(JAVA)   题目的大概意思就是有这样一块n*n的空地,每一小块儿代表一块空位或者一堵墙。图上的白色正方形代表空位,黑色正方形代表墙。圆形代表的是堡垒,每个堡垒可以攻击上下左右四个方向整排的其它堡垒,但是墙可以挡住堡垒的攻击。然后现在问在给定的一个地形当中最多可以放多少个堡垒且不会互相攻击。输入数据  输入数据包括了一个或多个地形的描述,用0代表输入数据结束。每一块地图的描述第一个数据是一个正整数,代表了这... 阅读详情

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.

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 nlines 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.

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
#include<iostream>  
#include<cstdio>  
#include<cstring>  
#include<string>  
#include<cstdlib>  
#include<algorithm>  
#include<cmath>  
using namespace std;  
int n,s,maxx;
char x[5][5];
int isok(int p,int q){
	for(int i=p-1;i>=0;--i){   //注意这里是倒着来的
		if(x[i][q]=='B')
			return 0;
		if(x[i][q]=='X')
			break;
	}
	for(int i=p+1;i<n;++i){
		if(x[i][q]=='B')
			return 0;
		if(x[i][q]=='X')
			break;
	}
	for(int j=q-1;j>=0;--j){   //注意这里是倒着来的
		if(x[p][j]=='B')
			return 0;
		if(x[p][j]=='X')
			break;
	}
	for(int j=q+1;j<n;++j){
		if(x[p][j]=='B')
			return 0;
		if(x[p][j]=='X')
			break;
	}
	return 1;  //这个格子的行列都没有炮弹或炮弹被障碍物挡住
}
void dfs(){
	if(s>maxx)
		maxx=s;
	for(int i=0;i<n;++i){   //每次都要遍历整张图
		for(int j=0;j<n;++j){
			if(x[i][j]=='.'&&isok(i,j)){
				s++;
				x[i][j]='B';
				dfs();
				s--;
				x[i][j]='.';
			}
		}
	}
}
int main(){
	while(cin>>n&&n!=0){
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				cin>>x[i][j];
			}
		}
		maxx=-1;
		s=0;
		dfs();
		cout<<maxx<<endl;
	}
	return 0;
}


ZOJ1002 Fire Net(二分图匹配) 这道题的预处理有点恶心,自己没写出来,参考了一下别人的代码 题目大意: 有一个N*N(N     地图 最大合法放置方案(不唯一)  一种合法但不最大方案       不合法方案 输入: 第1行:一个整型变量N 第2-N+1行:城市的构造('X'表示墙,'.'表示街道) 多组测试数据,以N=0结束。 输出: 对于每组测试数据仅输出一行,即能放置的最大碉堡数。 样例 阅读详情

相关推荐

n皇后问题C语言实现:在n*n的棋盘上放置n个皇后,要求皇后两两互斥,即任意两个皇后不能出现在同一行、同一列或同一条斜对角线上。 试求出所有的合法布局。

n皇后问题C语言实现:在n*n的棋盘上放置n个皇后,要求皇后两两互斥,即任意两个皇后不能出现在同一行、同一列或同一条斜对角线上。试求出所有的合法布局。

Fire Net 搜索 贪心

Fire Net<br />Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)<br />Total Submission(s): 1453    Accepted Submission(s): 811<br /><br />Problem DescriptionSuppose that we have a square city with straight streets. A map of

Rachel Zhang的专栏 2733

手眼标定(EyeToHand)推导

Base为基坐标系(B),工具末端坐标系(T),标定板为Mark坐标系(M),相机坐标系(C)对于每两个姿态都存在上式,组成一个AX=XB的矩阵方程,X为。此时转换成AX=0的问题,单纯用SVD求奇异解便可得到。相机坐标系到Base基坐标系下的转换关系。已知标定板与机械臂末端的相对位置固定不变,,即。带入(2)式求,至此求解出需要的手眼矩阵。在眼在手外的时候,其实是要求解。

stevenreally6的博客 1142

NYOJ587-blockhouses(DFS)

blockhouses 时间限制:1000 ms  |            内存限制:65535 KB 难度:3 描述 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 represen

YCH1035235541的专栏 2775

使用Jacob实现将Word文件转换为Pdf文件

如果是首次使用 jacob,建议先直接从 github上下载 zip包,因为在实现Word转Pdf的时候,不仅需要用到 jacob.jar,还需要 jacob.dll 库,而zip包中都有。官方使用文档可以参考:https://github.com/freemansoft/jacob-project/blob/main/docs/UsingJacob.md。// 如果安装的是微软的 Office,需要使用 Word.Application。

qq_41672950的博客 750

Windows系统的Mamba环境配置详细教程(状态空间模型)

causal_conv1d也是安装mamba的依赖必须库。安装完成后,通过pip list可以查看到安装的库。Triton是安装mamba的依赖,需要先安装。上述工作准备好后,按下面步骤安装。直接根据离线文件安装即可。是自己的虚拟环境名字。

2301_77831163的博客 3673

火力网

浙大ACM1002

程序碎片 847

Seurat 单细胞转录组测序数据分析教程(三)——python(scanpy)

文章参考至,做了一个更详细的解读。本教程探讨了 scanpy 的可视化可能性,分为三个部分:嵌入的散点图(例如 UMAP、t-SNE)使用已知标记基因鉴定簇差异表达基因的可视化在本教程中,我们将使用来自 10x 的数据集,其中包含来自PBMC的 68k 个细胞。Scanpy 在其分布中包括该数据集的简化样本,该数据集仅包含 700 个细胞和 765 个高度可变的基因。该数据集已经过预处理和 UMAP 计算。在本教程中,我们还将使用以下文献标记:B细胞:CD79A、MS4A1。

coffeeii的博客 5826

Fire Net HDU——1045 (搜索题)

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 blockhous...

forever_131514的博客 392

彻底卸载Ubuntu双系统,并完美回收100G空间给D盘

本文记录了安全卸载Ubuntu双系统并回收磁盘空间的全过程。作者首先通过Windows命令行彻底清除Ubuntu启动项,避免GRUB引导报错;随后在磁盘管理中删除Linux分区,将100G未分配空间合并至相邻的D盘。针对C盘空间不足问题,作者采用Dism++清理系统文件,并将用户文档、聊天记录等迁移至扩容后的D盘。最终实现了引导纯净、空间合理分配的目标,特别强调分区扩展必须遵循"相邻原则",建议通过间接迁移而非直接扩容来优化系统盘空间管理。

2403_85993278的博客 1512

【2026最新版】python点云处理算法汇总(长期更新版)

python点云处理算法整理。博客长期更新,最近一次更新时间为:2026年10月4日。

点云侠的博客 42万+

【Fire Net 】【HDU - 1045】(最大匹配—匈牙利算法)

题目: 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 cast...

哇哈哈哈的博客 308

【异常】Cursor 模型服务地域访问限制报错的完整排查与解决方案This model provider doesn‘t serve your region

其本质是:Cursor客户端依赖的上游大语言模型服务提供商,基于自身服务的合规运营范围,对客户端发起的请求进行了来源地域权限校验;当系统检测到请求的网络来源地域,不在该模型服务商官方授权提供服务的地域范围内时,会触发服务访问拦截策略,拒绝响应本次模型调用请求,最终在客户端抛出该报错。合规声明:本文所提供的所有方案,均仅用于技术问题排查与解决,请您在使用过程中严格遵守当地法律法规,以及对应软件与模型服务提供商的用户协议与合规要求。更多关于AI+教育领域的干货,可以关注我的微信公众号一时间获取哦~

奶爸的编程之路,也就一周冷个三天 1133

ZOJ-1002 Fire Net

题目链接:https://zoj.pintia.cn/problem-sets/91827364500/problems/91827364501 【题目大意】 n行n列的地图,地图中黑色格子代表墙壁(输入样例中的‘X’),可以挡住子弹。地图中的白色格子代表空地(输入样例中的’.’),可放置碉堡。碉堡可以发射子弹,被子弹射中的碉堡将会被摧毁。现需在地图中放置碉堡,放置要求如下:任意两个碉堡之间不能相互摧毁,即相同行和相同列都不能出现两个及两个以上碉堡,除非碉堡之间有墙壁阻挡子弹。在以上要求下,求在给定地图中能

qq_51776588的博客 825

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

zoj 1002 Fire Net(DFS~ 哈哈哈哈,终于过了!!!)

<br />1002 从一开始做ACM就郁闷的一道题,在1001下面它应该觉得压力很大啊!!哈哈。。<br /> <br />做完八皇后,党说这个能做了。。。<br /> <br />嘿嘿。这题是找放置最多数目的blockhouses(碉堡。。)使之不能同行同列,除非中间有个FIRENET。。。(同行同列就打中了。。)<br /> <br />开始想得比较复杂,按八皇后的思想,一行一行找,效果不好,一直不对,想明白了,一行不一定就放一个,一行也不一定放啊。。。当然,不放肯定全是防火墙了。。。<br /> <

小媛在努力~ 1万+

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

ZOJ 1002 Fire Net

简而言之,生成所有可能的碉堡放置方案,并通过判断每个方案是否合法,来寻找最大合法的碉堡数量。这个方法充分利用了暴力搜索和回溯的思想,通过递归遍历所有配置,最终找出最优解。

wuqingshun314159的博客 1148

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

ZOJ - 1002 Fire Net 【DFS】

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 s...

一定要站在自己热爱的生活里闪闪发光 3万+

zoj1002 fire net 。。dfs,用小媛话说:放在1001下面它应该压力很大啊!呵呵~~

“ 1002 从一开始做ACM就郁闷的一道题,在1001下面它应该觉得压力很大啊!!哈哈。。   做完八皇后,党说这个能做了。。。   嘿嘿。这题是找放置最多数目的blockhouses(碉堡。。)使之不能同行同列,除非中间有个FIRENET。。。(同行同列就打中了。。)   开始想得比较复杂,按八皇后的思想,一行一行找,效果不好,一直不对,想明白了,一行不一定就放一个,一行也不一定

XIAO! 676

ZOJ 1002 Fire Net 深度优先搜索算法

这道里原来我在看别人代码之前, 也写过。 洋洋洒洒的写了一个main函数四个嵌套for循环, 第一次的大手笔。运行结果没有问题, 但就是提交不上去, 还不收呢?搁置了好几天后, 没办法放弃。 后来看了一下别人的代码, 写完后提交编译错误, 都是因为跟系统函数重名缘故。  这道题的名头是,DFS(Depth-First-Search)深度优先搜索算法 #include "iostrea

fofu33的专栏 1156

zoj1002 Fire Net

//zoj1002 Fire Net //Accepted 1002 C++ 00:00.01 436K #include int n; int max; char map[5][5];

fairylan的专栏 1239

ZOJ 1002 Fire Net —— C++

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 tha...

点滴博客 415

Fire Net ZOJ - 1002 (dfs)

 Fire Net ZOJ - 1002 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 i...

Learning_is_endless的博客 268

ZOJ-1002 Fire Net

题目链接 ZOJ-1002 Fire Net 题意 给你一个n*n的图(n&lt;=4),‘X’代表墙壁,’ . '代表空地,问你这张图中最多可以放多少炮台(两个炮台不可以放在同行同列,除非中间有墙壁)? 思路 深搜,对于每一个位置,都有放炮台与不放两种选择,递归计算两种选择的最终放置炮台数,不断更新最大值即可。 该题的check函数比较巧妙,具体看代码注释。 #include&lt;iostr...

Herobrine的博客 418

[DFS]zoj1002 Fire Net

B - Fire Net Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatus Description Suppose that we have a square city with straight streets. A map of a city is a squ

童凌的技术博客 547

ZOJ-1002 Fire Net 火力网 题解

ZOJ-1002 Net Fire 火力网 题解 TAG:DFS

Mr. WA's Blog 2407
上一篇: 【百度之星初赛2】魔法因子|乘某个数首末位互换(数学,灵活题)
下一篇: hdu 1016 Prime Ring Problem(素数环,超时)
ccyy-
博客等级 码龄12年 31粉丝 244原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值