A - Fire Net
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 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.
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<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e12+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
int n,Max=0;
char a[6][6];
int check(int x,int y)
{
per(i,y-1,0)
{
if(a[x][i]=='x') return 0;
else if(a[x][i]=='X') break;
}
per(i,x-1,0)
{
if(a[i][y]=='x') return 0;
else if(a[i][y]=='X') break;
}
return 1;
}
void dfs(int deep,int sum)
{
int x=deep/n,y=deep%n;
if(deep>=n*n)
{
Max=max(Max,sum);
return ;
}
if(a[x][y]=='.')
{
if(check(x,y))
{
a[x][y]='x';
dfs(deep+1,sum+1);
a[x][y]='.';
}
}
dfs(deep+1,sum);
}
int main()
{
while(1)
{
Max=0;
sf("%d",&n);
if(!n) return 0;
mm(a,0);
rep(i,0,n)
sf("%s",&a[i]);
dfs(0,0);
pf("%d\n",Max);
}
}
A - Fire Net的更多相关文章
- 关于SequeezeNet中的Fire Module
在论文<SQUEEZENET: ALEXNET-LEVEL ACCURACY WITH 50X FEWER PARAMETERS AND <0.5MB MODEL SIZE>中,作者 ...
- FZU 2150 Fire Game
Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- Fire
Fire 分析: 首先,明确题意:b1,b2,--,bn 交换为b2,--,bn,b1,但这并不是意味着只能从b1开始交换,(这点从样例中可以看出),并且也不意味着交换的必须是连续的一串,可以是几个单 ...
- Android 轻量级输入校验库:Fire Eye
Fire Eye是一款轻量级简单易用的Android校验库. FireEye 2.0 在 1.0 的基础上,全部重写了代码,并优化了架构,性能上和逻辑上都大大提升.只需要几行代码,即可验证用户输入,并 ...
- ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪
FZU 2150 Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- UVA 11624 Fire!(广度优先搜索)
题目大意:在一个N*M的迷宫内,J代表某人(只有一个),F代表火(可能不只一个),#代表墙,火每分钟会向四周除了墙以外的地方扩散一层,问人能否在没被火烧到 之前逃出迷宫,若能逃出输出最短时间.很明显的 ...
- Amazon的Fire Phone之于Android开发者
在上周Amazon也耐不住加入了手机竞争行列之中,发布了自己的Fire Phone,于是Android家族又多了一位变种成员,Android系统的碎片化程度也进一步加剧.因为工作的关系,我有幸在上个月 ...
- Fire!(BFS)
Fire! Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Descr ...
- FZU Problem 2150 Fire Game
Problem 2150 Fire Game Accept: 145 Submit: 542 Time Limit: 1000 mSec Memory Limit : 32768 KB P ...
- hdu 1045:Fire Net(DFS经典题)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
随机推荐
- WHY数学表达式的3D可视化
WHY数学表达式的3D可视化 很早之前我就有这种想法,将数学表达式的图形显示出来.最近终于实现了这套较为完善的版本,将其代码公布,也为开源做点贡献.首先系统中定义一套脚本语言格式,用于描述数学表达式. ...
- 如何自动播放光盘、解决win7电脑不能播放光盘
如何设置光盘自动播放.允许光盘自动运行呢? 在使用电脑光驱播放光盘文件的时候,经常出现的一个问题是,光驱不能自动播放光盘,但是打开光盘的文件手动操作没有任何问题,这给使用造成了很多麻烦.那么,如何让光 ...
- zabbix用户管理
zabbix用户管理,主要包括用户增删改查.用户报警媒介管理.用户权限管理. 安装完zabbix后,已经自带了两个用户Admin和Guests 超级管理员默认账号:Admin,密码:zabbix,这是 ...
- iOS 自动移除KVO观察者
对NSObject写一个分类: #import <Foundation/Foundation.h> @interface NSObject (FMObserverHelper) - (vo ...
- LeetCode OJ 238. Product of Array Except Self 解题报告
题目链接:https://leetcode.com/problems/product-of-array-except-self/ 238. Product of Array Except Se ...
- vue-worker的介绍和使用
vue-worker把复杂的web worker封装起来,提供一套非常简明的api接口,使用的时候可以说像不接触worker一样方便.那么具体怎么使用呢? 安装 npm i -S vue-worker ...
- elast alert
参考文档:<elast alert> 假设报错的内容为: ceph-rest-api service down At least 1 events occurred between 201 ...
- 【iCore4 双核心板_ARM】例程二十一:LWIP_TCP_SERVER实验——以太网数据传输
实验现象: 核心代码: int main(void) { system_clock.initialize(); led.initialize(); adc.initialize(); delay.in ...
- Tomcat配置多个域名绑定到不同项目
<Host name="www.dn-serve.com" appBase="webapps" unpackWARs="true" a ...
- azkaban在centos下的部署安装
azkaban 是一个用Java开发的开源调度工具workflow. 下面介绍具体安装过程,我这里使用的版本是3.43.0,使用的是solo运行模式. 编译 git clone https://git ...