Fire Net--hdu1045
Fire Net
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7929 Accepted Submission(s):
4521
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.
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 n lines 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.
maximum number of blockhouses that can be placed in the city in a legal
configuration.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char map[][];
int n,now,ibest,current;
bool canput(int row,int col)//判断能不能放
{
int i;
for(i=row-;i>=;i--)//判断行
{
if(map[i][col]=='O')
return false;
if(map[i][col]=='X')
break;
}
for(i=col-;i>=;i--)//判断列
{
if(map[row][i]=='O')
return false;
if(map[row][i]=='X')
break;
}
return true;
}
void dfs(int k,int current)
{
int x,y;
if(k==n*n)//如果遍历完就返回
{
if(current>ibest)//更新最大的个数
ibest=current;
return ;
}
else
{
x=k/n;
y=k%n;
if(map[x][y]=='.'&&canput(x,y))
{
map[x][y]='O';
dfs(k+,current+);//下一次递归
map[x][y]='.';
}
dfs(k+,current);//当前不放碉堡
}
}
int main()
{
while(scanf("%d",&n),n)
{
getchar();
int k=,i;
ibest=;
current=;
for(i=;i<n;i++)
scanf("%s",map[i]);
dfs(,);
printf("%d\n",ibest);
}
return ;
}
Fire Net--hdu1045的更多相关文章
- HDU1045 Fire Net(DFS)
题目链接: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) Me ...
- HDU1045 Fire Net(DFS枚举||二分图匹配) 2016-07-24 13:23 99人阅读 评论(0) 收藏
Fire Net Problem Description Suppose that we have a square city with straight streets. A map of a ci ...
- HDU1045:Fire Net(二分图匹配 / DFS)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDU1045 Fire Net —— 二分图最大匹配
题目链接: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: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- hdu1045 Fire Net
在一张地图上建立碉堡(X),要求每行没列不能放两个,除非中间有强挡着.求最多能放多少个碉堡 #include<iostream> #include<cstdio> #inclu ...
- hdu1045 Fire Net---二进制枚举子集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意: 给你一幅n*n的图,再给你一些点,这些点的上下左右不能再放其他点,除非有墙('X') ...
- 【HDU-1045,Fire Net-纯暴力简单DFS】
原题链接:点击! 大致题意:白块表示可以放置炮台的位置——每个炮台可以攻击到上下左右的直线上的炮台(也就是说在它的上下左右直线上不可以再放置炮台,避免引起互相攻击),黑块表示隔离墙的位置——不可放 ...
- Fire Net(HDU-1045)(匈牙利最大匹配)(建图方式)
题意 有一个 n*n 的图,. 代表空白区域,X 代表墙,现在要在空白区域放置结点,要求同一行同一列只能放一个,除非有墙阻隔,问最多能放多少个点 思路 只有在墙的阻隔情况下,才会出现一行/列出现多个点 ...
随机推荐
- [C++程序设计]内置函数
注意: 可以在声明函数和定义函数时同时写 inline,也可以只在其中一处声明inline,效果相同,都能按内置函数处理. 使用内置函数可以节省运行时间,但却增加了目标 程序的长度.因此一般只将规模很 ...
- sublime快捷键收藏
快速查找(ctrl + P)输入@+函数名可以快速找到函数.输入#+文本可以快速进行文件内文本匹配.3. 多行游标功能(ctrl + D,非常实用)如何将文件中的某个单词更改为另一个?方法一:利用查找 ...
- 谈一谈JVM内存JAVA_OPTS参数
最近几个月,做的性能测试项目中,发现了一些内存方面的问题,其中有涉及到对JBOSS里的JAVA_OPTS配置,例如一下所示: JAVA_OPTS="-server -Xms1536m -Xm ...
- 手机天猫nba项目总结
页面逻辑: 技术统计 比赛竞猜 猜你喜欢 进入页面时,获取服务器的当前时间.然后进行页面上的每秒递增.1.每隔n秒向后台发送请求,获取最新比分信息,球队图像,球员信息.然后更改页面.2.每隔n秒向后台 ...
- Socket基础(一)
OSI七层模型: 物理层:比特,数据链路层:帧,网络层:包,传输层及以上:报文.因为不用,不做详解. TCP/IP模型:这个常用,详解. 链路层:负责在两个相邻节点上线路上的无差错传输数据,以帧为单位 ...
- javascript 之 location.href、跨窗口调用函数
location.href这个东西常常用于跳转,location既是window对象的属性,又是document对象的属性. JavaScript hash 属性 -- 返回URL中#符号后面的内容 ...
- Eclipse IDE for Java EE Developers使用和新建工程helloworld
开发j2ee还是用专门的java ee eclipse,自带了许多开发j2ee的插件,包括: This package includes: Data Tools Platform Eclipse Gi ...
- Valid Palindrome 解答
Question Given a string, determine if it is a palindrome, considering only alphanumeric characters a ...
- Perl Symbolic Reference
看一些模块的代码,很多时候通过*glob的方式来改变变量或者函数,这种方法称为Symbolic reference. 首先看一下*glob的结构,这个在之前的博文已经讲过,不做细述: SV = PVG ...
- ZOJ问题(坑死了)
ZOJ问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...