ACM-Fire Net
输入
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.
样例输入
4
.X..
....
XX..
....
2
XX
.X
3
.X.
X.X
.X.
3
...
.XX
.XX
4
....
....
....
....
0
样例输出
5
1
5
2
4
这道题看着麻烦,实际就是讲了棋盘放位置的策略。总体和n皇后问题很类似。
// Fire Net.cpp : 定义控制台应用程序的入口点。
// //解题思路:
//1.类似n皇后问题,上下左右不能有重复,只检测上方和左方即可,下面的没有放到,不需要检查。
//2.走斜角坐标,x = pos/n,y = pos % n
//3.每个坐标存在能放和不能放两种情况 #include "stdafx.h" #include <stdio.h>
#include <string.h> #define M 10
int n,ans;
char map[M][M]; int check(int x, int y)
{
if (map[x][y] == 'X') return ; //左方
for (int col = y - ; col >= ; col--)
{
if (map[x][col] == 'X')
break;
if (map[x][col] == '#')
return ;
} //上方
for (int row = x - ; row >= ; row--)
{
if (map[row][y] == 'X')
break;
if (map[row][y] == '#')
return ;
} return ; } void DFS(int pos, int sum)
{
int x = pos / n, y = pos % n;//x,y 的位置
if (pos == n * n)
{
ans = ans > sum? ans:sum;
return;
}
if (check(x, y))
{
map[x][y] = '#';
DFS(pos + , sum + );
map[x][y] = '.';
} DFS(pos + , sum);
} int main()
{
while (~scanf("%d", &n) && n)
{
memset(map, '\0', sizeof(map)); for (int i = ; i < n; i++)
scanf("%s", &map[i]); ans = ;
DFS(,);
printf("%d\n", ans); }
return ;
}
ACM-Fire Net的更多相关文章
- ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪
FZU 2150 Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- 【Acm】算法之美—Fire Net
题目概述:Fire Net Suppose that we have a square city with straight streets. A map of a city is a square ...
- [acm 1002] 浙大 Fire Net
已转战浙大 题目 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=2 浙大acm 1002 #include <iostre ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- HDU1045 Fire Net(DFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- ACM -二分图题目小结
暂时只包括与最大匹配相关的问题. 求最大独立集,最小路径覆盖等等大多数题目都可以转化为求最大匹配用匈牙利算法解决. 1.最大匹配(边集) 此类问题最直接,直接用匈牙利算法即可. HDU 2063 过 ...
- hdu 1045 Fire Net(最小覆盖点+构图(缩点))
http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS Memory Limit:32768KB ...
- zoj 3820 Building Fire Stations 树的中心
Building Fire Stations Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge ...
- HDU-1045 Fire Net
http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) Me ...
- (FZU 2150) Fire Game (bfs)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2150 Problem Description Fat brother and Maze are playing ...
随机推荐
- jqGrid 重新加载数据
参考:https://blog.csdn.net/u012746051/article/details/52949353 $("#列表区域id").jqGrid('clearGri ...
- PAT乙级完结有感
去年10月开始刷的题,拖拖拉拉的终于借这个假期刷完了,总的来说还是有点小激动的,毕竟,第一次刷完一个体系,在这之前,我在杭电.南阳.洛谷.leetcode.以及我们自己学校的OJ上刷过,但都没有完完整 ...
- 新闻网大数据实时分析可视化系统项目——3、Hadoop2.X分布式集群部署
(一)hadoop2.x版本下载及安装 Hadoop 版本选择目前主要基于三个厂商(国外)如下所示: 1.基于Apache厂商的最原始的hadoop版本, 所有发行版均基于这个版本进行改进. 2.基于 ...
- Windows系统(服务器)忘记管理员登录密码:
windows sever2003忘记密码:使用老毛桃PE进入然后修改密码,重启即可. windows sever2008忘记密码:可按该网址的方法即可解决:http://www.jb51.net/a ...
- 启动kafka报错
启动kafka时 报错: kafka-console-consumer.sh --from-beginning --zookeeper node01:8121,node02:8121,node03:8 ...
- Manjro i3 桌面 添加输入法 及无声音配置方法(This sound device does not have any capture controls.问题)
一.i3桌面添加输入法 1.把配置写在 /etc/environment中 export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx export XM ...
- java与MySQL数据库的连接
java与MySQL数据库的连接 1.数据库的安装和建立参见上一篇博客中的第1,2步骤.(http://blog.csdn.net/nuptboyzhb/article/details/8043091 ...
- 【Luogu4448】 [AHOI2018初中组]球球的排列
题意 有 \(n\) 个球球,每个球球有一个属性值 .一个合法的排列满足不存在相邻两个球球的属性值乘积是完全平方数.求合法的排列数量对 \(10^9+7\) 取膜. \(n\le 300\) (本题数 ...
- 设备树DTS 学习:2-设备树语法
背景 通过上一讲了解完设备树DTS有关概念,我们这一讲就来基于设备树例程,学习设备树的语法规则. 参考:设备树详解dts.设备树语法详解.设备树使用总结 设备树框架 1个dts文件 + n个dtsi文 ...
- 802.11X用户身份验证
静态WEP企图同时解决802.11无线网络安全的两个问题.它即打算提供身份验证以限定拥有特定密钥方能进行网络访问,也想要提供机密性以在数据经过无线链路时予以加密.然而,它在这两方面的表现都不是特别好. ...