blockhouses



题意 : 给你一张图上面" X " 代表墙 , " . " 代表空地 , 让你在空地上放置炮台 , 条件是 不能 让彼此的炮台 可以互相看见 ( 隔着墙就看不见了 ) , 问你最多可以放置 多少个炮台 .
题解 : 二话不说上去直接暴力搜索 , 给的图最大不超过 5 * 5 所以 就直接暴力 了 , 但是 八皇后那里以前写过一个 0ms 的代码 , 一会去看看 , 一段时间不看就忘了 , 一会附上优化代码 . 还有就是 这个将两个for循环写成一个for循环 真的特别简单 而且还不容易出错 ...
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<cctype>
using namespace std; //有点类似于 八皇后问题
char a[][]; //图 不大 可以暴力一点
int visited[][],maxn,n1,result;
bool check(int x,int y,int n)
{
for(int i=x-;i>=&&a[y][i]!='X';i--)
if(a[y][i]=='@')
return false;
for(int i=x+;i<n&&a[y][i]!='X';i++)
if(a[y][i]=='@')
return false;
for(int i=y-;i>=&&a[i][x]!='X';i--)
if(a[i][x]=='@')
return false;
for(int i=y+;i<n&&a[i][x]!='X';i++)
if(a[i][x]=='@')
return false;
return true;
}
void DFS(int x,int n)
{
for(int i=x;i<n1;i++)
{
int i1=i/n,j1=i%n;
if(a[i1][j1]!='X'&&!visited[i1][j1]&&check(j1,i1,n))
{
visited[i1][j1]=;
a[i1][j1]='@';
maxn++;
result=maxn>result?maxn:result;
DFS((j1+)*(i1+),n);
maxn--;
a[i1][j1]='.';
visited[i1][j1]=;
}
}
}
int main()
{
int n;
while(scanf("%d",&n),n)
{
n1=n*n;
for(int i=;i<n1;i++)
{
int i1=i/n,j1=i%n;
scanf(" %c",&a[i1][j1]);
}
result=maxn=;
memset(visited,,sizeof(visited));
DFS(,n);
printf("%d\n",result);
}
return ;
}
blockhouses的更多相关文章
- ACM blockhouses
blockhouses 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 Suppose that we have a square city with straigh ...
- NYOJ 587 blockhouses 【DFS】
blockhouses 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 Suppose that we have a square city with straigh ...
- [ACM_图论] Fire Net (ZOJ 1002 带障碍棋盘布炮,互不攻击最大数量)
Suppose that we have a square city with straight streets. A map of a city is a square board with n ...
- hdu 1045:Fire Net(DFS经典题)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- 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:1000MS Memory Limit:32768KB ...
- Fire Net
Fire Net Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- HDU-1045 Fire Net
http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) Me ...
- hdoj 1045 Fire Net
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
随机推荐
- linux strings-在对象文件或二进制文件中查找可打印的字符串
推荐:更多Linux 文件查找和比较 命令关注:linux命令大全 strings命令在对象文件或二进制文件中查找可打印的字符串.字符串是4个或更多可打印字符的任意序列,以换行符或空字符结束. str ...
- Servlet的说明及使用案例
Servlet的说明及使用案例 制作人:全心全意 Servle的基础介绍 Servlet结构体系 Servlet对象.ServletConfig对象与Serializable对象是接口对象,其中Ser ...
- 03 Python的那些事
目录: 1) 创始人以及重要发展历程 2) Python语言的特点 3) TIOBE排名 4) 解释器 5) Python后缀名 6) 变量规则和约定 7) 常量 8) 注释 9) 缩进 10) Py ...
- 第十三节:web爬虫之Redis数据存储
下面仅仅展示Redis的set()集合存储,并不完整,后期会对Redis进行全面的介绍.... 此时数据已经存储到Redis当中
- 嵌入式LinuxC语言程序设计基础教程
第1章 嵌入式LinxuC语言开发工具 第2章 数据 第3章 数据的输入输出 第4章 运算符和表达式 第5章 程序结构和控制语句 第6章 数组 第7章 指针 第8章 函数 第9章 用户自定义数据类型 ...
- MSSQL获取指定日期的SQL语句
--1.一个月第一天的 SELECT DATEADD(mm,DATEDIFF(mm,0,getdate()),0) --2.本周的星期一 SELECT DATEADD(wk,DATEDIFF(wk,0 ...
- 【Codeforces 1102E】Monotonic Renumeration
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 会发现如果a[i]=a[j] 那么b[i]~b[j]都是相同的,等于b[i] 而b[i]等于b[i-1]+1或者b[i] 有两种可能 所以对于 ...
- jquery追加元素的几种方法(append()、prepend()、after()、before()、insertAfter()、insertBefore())
最近项目不是很忙,抽空整理了下,js中常用追加元素的几种方法. <!DOCTYPE html> <html> <head> <meta charset=&qu ...
- 食物链 2001年NOI全国竞赛
时间限制: 3 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A吃B ...
- F - Experienced Endeavour 矩阵快速幂
Alice is given a list of integers by Bob and is asked to generate a new list where each element in t ...