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 ...
随机推荐
- Oracle 密码文件
一.密码文件 作用:主要进行DBA权限的身份认证 DBA用户:具有sysdba,sysoper权限的用户被称为dba用户.默认情况下sysdba角色中存在sys用户,sysoper角色中存在syste ...
- Mysql Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode
今天用mysql workbench在更新数据的时候,出现了下面错误:15:52:39 update wp_posts set post_content = replace(post_conte ...
- 洛谷 2824 [HEOI2016/TJOI2016]排序
[题意概述] 对一个1到n的排列做m次区间排序,最后询问位置q上面的数. [题解] 区间排序的效率是nlogn,所以暴力做的话效率是mnlogn,显然达不到要求. 我们考虑二分答案.如果某个位置的数比 ...
- RabbitMq的简单使用
本篇将介绍RabbitMq的一个简单使用例子,分别介绍生产者如何发送消息,消费者如何接收和处理消息 关于RabbitMQ的知识背景的文章非常多.我对它的总结是,解决高并发请求的瓶颈,将应用程序真正处理 ...
- 关于zookeeper和zkfc的一些测试
1.停掉zookeeper集群 ****进程影响****** zkfc:报错无法连接zookeeper.ClientCnxn java.net.connectexception:拒绝连接,但不会shu ...
- 浅谈href=与href=javascript_void(0)的区别
"#"包含了一个位置信息.默认的锚点是#top 也就是网页的顶端.而javascript:void(0) 仅仅表示一个死链接,这就是为什么有的时候页面很长,浏览链接明明是#可是跳 ...
- Spring常用注解总结 hibernate注解
1.@Resource和@Autowired @Resource和@Autowired功能一样在容器查找匹配的Bean @Autowired默认按照byType方式进行bean匹配,@Resource ...
- RabbitMQ-linux安装rabbitmq(二)
说明 本地装了个虚拟机模拟集群 所以记下安装步骤 安装Erlang 安装类库 yum -y install ncurses-devel yum -y install openssl-devel yum ...
- 清北学堂模拟赛d1t2 火柴棒 (stick)
题目描述众所周知的是,火柴棒可以拼成各种各样的数字.具体可以看下图: 通过2根火柴棒可以拼出数字“1”,通过5根火柴棒可以拼出数字“2”,以此类推. 现在LYK拥有k根火柴棒,它想将这k根火柴棒恰好用 ...
- poj 2823单调队列模板题
#include<stdio.h>//每次要吧生命值长的加入,吧生命用光的舍弃 #define N 1100000 int getmin[N],getmax[N],num[N],n,k, ...