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 ...
随机推荐
- Configuring HDFS High Availability
Configuring HDFS High Availability 原文请訪问 http://blog.csdn.net/ashic/article/details/47024617,突袭新闻小灵儿 ...
- rotate-function
https://leetcode.com/problems/rotate-function/ public class Solution { public int maxRotateFunction( ...
- Informatica 常用组件Source Qualifier之九 创建SQ转换
可以配置 Designer 在您将源拖到映射中时默认创建源限定符转换,您也可以手动创建源限定符转换. 默认创建源限定符转换 可以配置 Designer 在您将源拖到映射中时自动创建一个源限定符转换. ...
- 第三章 类文件结构与javap的使用
注:本文主要参考自<深入理解java虚拟机(第二版)> 1.javap的使用与类文件结构 使用过程: java源代码: package compile; /** * class字节码 */ ...
- Iterator 迭代器模式 MD
迭代器模式 简介 Iterator模式是行为模式之一,它把对容器中包含的内部对象的访问[委让]给外部类,使用Iterator按顺序进行遍历访问. 在程序设计中,经常有这种情况:需要从大量的数据集合中一 ...
- C# WCF 完整实例,winform 窗体作为 宿主
上一次提到,我们的WCF程序宿主是发布到IIS上面的.虽然这样做未尝不可,不过不便于我们进行“开始”或“停止”WCF服务的操作.所以再次尝试了编写以窗体应用程序作为WCF服务宿主的方式,并取得了成功. ...
- Realm Swift
Realm Swift 当前这个翻译,主要是方便我自己查阅api,有非常多地方写的比較晦涩或者没有翻译,敬请谅解 version 0.98.7 官方文档 參考文献 Realm支持类型 String,N ...
- Cognos定时Email发送报表数据功能
1:进入 IBM Cognos Configuration-Data Access-Notification 2:设置如下(注意一定要是smtp服务,端口25,我这里是用了腾讯邮箱的smtp服务) 当 ...
- Retrofit2+Rxjava+MVP实践
此博文根据前面两篇文章 Android MVP 架构初试 Android MVP 架构封装 再结合主流框架Retrofit2+Rxjava来个实践 源码地址RxMVP 项目截图 Retrofit2+R ...
- linux内核——进程管理
在讲进程之前先说一下进程的堆栈的吧: 1.进程的堆栈 内核在创建进程的时候,在创建task_struct的同一时候,会为进程创建对应的堆栈.每一个进程会有两个栈,一个用户栈.存在于用户空间,一个内核栈 ...