HDU-1045 Fire Net
http://acm.hdu.edu.cn/showproblem.php?pid=1045
Fire Net
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6756 Accepted Submission(s): 3829
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<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,c[][];
char str[][];
int map[][];
int mmax;
bool judge(int row,int col) //判断是否可以放置
{ //在遇到墙之前同行或同列上已放置,则不能再放
int i;
for(i=col-;i>=;i--)
{
if(map[row][i]==) return false;
if(str[row][i]=='X') break;
} for(i=row-;i>=;i--)
{
if(map[i][col]==) return false;
if(str[i][col]=='X') break;
} return true;
}
void dfs(int x,int y,int num)
{
if(x==n)
{
if(num>mmax)
mmax=num;
return ;
}
else
{
// printf("x=%d,y=%d,num=%d\n",x,y,num);
if(y<n)
{
if(str[x][y]=='.'&&judge(x,y))
{
map[x][y]=;
dfs(x,y+,num+);
map[x][y]=;
}
dfs(x,y+,num);
}
else
dfs(x+,,num); }
}
int main()
{
while(~scanf("%d",&n))
{
int i;
memset(map,,sizeof(map));
if(n==)
break;
mmax=;
for(i=; i<n; i++)
scanf("%s",str[i]);
dfs(,,);
printf("%d\n",mmax);
}
return ;
}
HDU-1045 Fire Net的更多相关文章
- 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:1000MS Memory Limit:32768KB ...
- HDU 1045(Fire Net)题解
以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] 给定大小的棋盘中部分格子存在可以阻止互相攻击的墙,问棋盘中可以放置最多多少个可以横纵攻击炮塔. [题目分析] 这题本来在搜索专题 ...
- 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——————【最大匹配、构图、邻接矩阵做法】
Fire Net Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- 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 题意: 在一个n*n地图中,有许多可以挡住子弹的墙,问最多可以放几个炮台,使得炮台不会相互损害.炮台会向四面发射子弹. 思路: 把行列分开做,先处理行,把同一行中相互联通的点缩成一个 ...
- HDU - 1045 Fire Net(二分匹配)
Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...
- HDU - 1045 Fire Net(搜索)
Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...
随机推荐
- Google Android SDK开发范例------------20141119
一.Edit和Checkbox完成对登陆密码的查看:添加Edit的setOnCheckedChageListener和对CheckBox的状态通过isCHecked判断 大体代码如下 CheckBox ...
- c++ primer复习(三)
1 istream.ostream类型,cin.cout.cerr是istream或ostream类型的具体的对象,<<和>>是操纵符 getline函数的参数是istream ...
- jQuery查看dom元素上绑定的事件列表
jQuery API提供了一种能够查看元素已绑定事件的列表,这个功能在进行功能调试的时候特别有用,尤其确定在代码执行过程中元素绑定的事件是否被更改. 1: jQuery( elem ).dat ...
- ubuntu 初始
1.命令行界面与图形界面 ctrl + alt + f1进入命令行界面 ctrl + alt + f7 切换图形界面 2.ubuntu 的wubi安装与卸载 第一:在win 系统下启动DOS,进入命令 ...
- demo_07选择器练习
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- JDK重要包和Java学习方法论
以下内容摘自:万能的林萧说:一篇文章教会你,如何做到简历中要求的“要有扎实的Java基础” 第一级别:精读源码 该级别包含的包如下: java.io java.lang java.util 第二 ...
- Spring-Boot-XML-Restful-Service
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-write-an-xml-rest-service ...
- css3 标题超过长度自动省略号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 全面理解.htaccess语法中RewriteCond和RewriteRule意义
RewriteCond的语法 RewriteCond TestString CondPattern [Flags]其中的TestString是指一个文本格式的条件,例子中用的是环境变量名HTTP_HO ...
- Scala的Option类型
Scala的Option类型 为了让所有东西都是对象的目标更加一致,也为了遵循函数式编程的习惯,Scala鼓励你在变量和函数返回值可能不会引用任何值的时候使用Option类型.在没有值的时候,使用No ...