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 ...
随机推荐
- C#中流的读写器BinaryReader、BinaryWriter,StreamReader、StreamWriter详解【转】
https://blog.csdn.net/ymnl_gsh/article/details/80723050 C#的FileStream类提供了最原始的字节级上的文件读写功能,但我们习惯于对字符串操 ...
- 利用useragent判断移动设备
用 User Agent 判断移动设备 WebApp除了做成响应式设计以外,还可以给移动设备做一套UI,PC端再做一套UI,然后在前台进行判断进行相应的跳转.判断是否是移动设备一般根据浏览器的user ...
- 安装babel遇到的异常
Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure ...
- 绝对精品推荐做前端的看下:Web前端开发体会十日谈
20151208感悟: 前端人的角度来看的话,感觉像是阅读一个大牛前端的全部武功的一个秘籍说明,里面的思想高价值蛋白真是太多太多,推荐看. Web前端开发体会十日谈 一直想写这篇“十日谈”,聊聊我对W ...
- Django Web开发学习笔记(1)
一.Python的标准类型 (1)bool型 >>> bool("") False >>> bool(None) False >>& ...
- struts2:表单标签续(datetimepicker标签)
18. datetimepicker标签 18.1 拷贝JAR包 在struts-2.x.x压缩包的lib目录中拷贝struts2-dojo-plugin-2.3.8.jar到WEB-INF/lib目 ...
- Atitit phpstorm配置attilax总结
Atitit phpstorm配置attilax总结 1. 前期准备 1 1.1. 配置interpreter 1 1.2. debug需要xdebug的支持,不管是script模式还是web模式 3 ...
- Atitit 翻页功能的解决方案与版本历史 v4 r49
Atitit 翻页功能的解决方案与版本历史 v4 r49 1. 版本历史与分支版本,项目版本记录1 1.1. 主干版本历史1 1.2. 分支版本 项目版本记录.1 2. Easyui 的翻页组件2 ...
- [docker] macvlan最佳实战
macvlan和ipvlan的对比 http://hicu.be/macvlan-vs-ipvlan macvlan ipvlan 参考: https://yq.aliyun.com/articles ...
- [svc]openssl对称非对称加密实战
OpenSSL进行aes加密解密-对称加密(symmetry) 建立文件test.txt, 特意写入中英文 # cd /tmp # echo "test测试" > test. ...