【HDOJ1045】【DFS】
http://acm.hdu.edu.cn/status.php?user=MekakuCityActors&pid=1045&status=5
Fire Net
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14308 Accepted Submission(s): 8668
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 <stdio.h>
#include <string.h>
#include <algorithm>
#include<iostream>
using namespace std;
char Map[][];
int res;
int n;
/**
判断是否成立
*/
bool judge(int x,int y){
if(Map[x][y]!='.')return false; //X.S都不可以放
for(int i=x-;i>=;i--){//判断点的上方
if(Map[i][y]=='X')break;
if(Map[i][y]=='O')return false;
}
for(int i=y-;i>=;i--){//判断点的左方
if(Map[x][i]=='X')break;
if(Map[x][i]=='O')return false;
}
return true;
}
/**
DFS
*/
void DFS(int x,int y,int tot){
if(x==n&&y==){ //已经搜索了n行,求最大值
res=max(res,tot);
return;
}
if(y==n){ //这一行已经求完,从下一行第一列重新开始
DFS(x+,,tot);
return;
}
for(int i=y;i<n;i++){
if(judge(x,i)){
Map[x][i]='O';
DFS(x,i+,tot+);
Map[x][i]='.';
}
}
DFS(x+,,tot);//上一行搜索结束,从下一行重新开始
}
int main(){
while(scanf("%d",&n),n){
res=;
for(int i=;i<n;i++)
scanf("%s",Map[i]);
DFS(,,);
printf("%d\n",res);
}
return ;
}
【HDOJ1045】【DFS】的更多相关文章
- Codeforces 383C . Propagating tree【树阵,dfs】
标题效果: 有一棵树,有两种操作模式对本树:1:表示为(1 x val),在NOx加在节点上val,然后x每个节点加上儿子- val.给每个儿子一个儿子在一起-(- val),加到没有儿子为止.2:表 ...
- [USACO08DEC]在农场万圣节Trick or Treat on the Farm【Tarja缩点+dfs】
题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定奶牛必须遵 ...
- HDU 5409 CRB and Graph 【点双连通+DFS】
<题目链接> 题目大意: 给你一个连通的无向图,问你删除每一条边后,是否能够出现一对(u,v),使得u,v不连通,且u<v,如果有多对u,v,则输出尽量大的u,和尽量小的v. 解题分 ...
- ZOJ - 3761 Easy billiards 【并查集+DFS】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3761 题意 在一个桌面上,给出一些球 如果在A球的某个方向的前方 ...
- bzoj 1770: [Usaco2009 Nov]lights 燈【高斯消元+dfs】
参考:https://blog.csdn.net/qq_34564984/article/details/53843777 可能背了假的板子-- 对于每个灯建立方程:与它相邻的灯的开关次数的异或和为1 ...
- 【I'm Telling the Truth】【HDU - 3729】 【匈牙利算法,DFS】
思路 题意:该题主要说几个同学分别说出自己的名次所处区间,最后输出可能存在的未说谎的人数及对应的学生编号,而且要求字典序最大. 思路:刚刚接触匈牙利算法,了解的还不太清楚,附一个专门讲解匈牙利算法的博 ...
- 比特镇步行(Walk)【虚点+bfs+dfs】
Online Judge:NOIP2016十连测第一场 T3 Label:虚点,bfs,dfs 题目描述 说明/提示 对于100%数据,\(n<=200000\),\(m<=300000\ ...
- 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)B 杨老师的游戏【暴力/next-permutation函数/dfs】
链接:https://www.nowcoder.com/acm/contest/116/B 来源:牛客网 题目描述 杨老师给同学们玩个游戏,要求使用乘法和减法来表示一个数,他给大家9张卡片,然后报出一 ...
- 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】
目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...
- 【DFS】NYOJ-82 迷宫寻宝(一)-条件迷宫问题
[题目链接:NYOJ-82] #include<iostream> #include<cstring> using namespace std; struct node{ in ...
随机推荐
- WPF客户端实现.net升级
客户端.net版本由3.5升级到4.5,首先把.net4.5的离线安装包添加到资源,程序运行的时候,从资源中生成离线安装包,并通过传递参数的方式执行静默安装命令,具体代码如下: private sta ...
- PAT-GPLT训练集 L1-039 古风排版
PAT-GPLT训练集 L1-039 古风排版 注意:在输入字符串时,最后一个字符为'\0', 虽然输出时显示为空格,但是系统检查为‘\0’!!! 代码: #include<stdio.h> ...
- 网卡驱动-BD详解(缓存描述符 Buffer Description)
DMA介绍(BD的引入) 网络设备的核心处理模块是一个被称作 DMA(Direct Memory Access)的控制器,DMA 模块能够协助处理器处理数据收发.对于数据发送来说,它能够将组织好的数据 ...
- chrome console 阻止 Navigated to
阻止如图 chrome 如图信息
- [转载] JAVA面试题和项目面试核心要点精华总结(想进大公司必看)
JAVA面试题和项目面试核心要点精华总结(想进大公司必看) JAVA面试题和项目面试核心要点精华总结(想进大公司必看)
- 关于vivado implement后clock interaction报告的理解(更新中)
对于较大工程很难避免遇到CDC问题,vivado自带的分析工具可以报告跨时钟状态. 详情参看手册UG906-Design Analysis and Closure Techniques. (1)关于p ...
- 在linux执行kettle
1.下载 最新版下载 7.1 https://community.hitachivantara.com/docs/DOC-1009855 2.准备 3.上传任务文件 .kjb,.ktr 4.上传mys ...
- Java语法基础学习DayFour
一.面向对象 1.特点: A:是一种更符合我们思考习惯的思想B:把复杂的事情简单化C:让我们从执行者变成了指挥者 2.使用: a:创建对象格式类名 对象名 = new 类名();b:如何使用成员变量和 ...
- bootstrap --- 在 modal中的 datetimepicker 关闭 ,会造成 modal也会被关闭.
这个大概是事件冒泡造成的. 解决办法: <form id="userForm" class="form-horizontal"> <input ...
- ios中 pickerView的用法
今天是一个特殊的日子(Mac pro 敲的 爽... 昨天到的) // // QRViewController.m// #import "QRViewController.h" @ ...