codeforces 598D Igor In the Museum
题目链接:http://codeforces.com/problemset/problem/598/D
题目分类:dfs
题目分析:处理的时候一次处理一片而不是一个,不然会超时
代码:
#include<bits/stdc++.h> using namespace std; int n,m,k,a,b,ii;
int ans;
char ch[][];
int dx[]={,,,-};
int dy[]={,-,,};
int dp[][];
int p[]; void dfs(int x,int y)
{
if(x>n||x<||y>m||y<)
return ;
if(ch[x][y]=='*')
{
ans++;
return ;
}
if(dp[x][y]!=)
return; dp[x][y]=ii;
for(int i=;i<;i++)
{
int temp_x=x+dx[i];
int temp_y=y+dy[i];
dfs(temp_x,temp_y);
}
return;
} int main()
{
cin>>n>>m>>k;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
cin>>ch[i][j];
}
} for(ii=;ii<=k;ii++)
{
cin>>a>>b;
ans=;
if(!dp[a][b])
dfs(a,b);
else
ans=p[dp[a][b]];
p[ii]=ans;
cout<<ans<<endl;
}
return ;
}
codeforces 598D Igor In the Museum的更多相关文章
- 【CodeForces - 598D】Igor In the Museum(bfs)
Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...
- Codeforces 598D:Igor In the Museum
D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集
D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...
- [BFS]Codeforces Igor In the Museum
Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Igor In the Museum(搜搜搜151515151515******************************************************1515151515151515151515)
D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces 598D (ccpc-wannafly camp day1) Igor In the Museum
http://codeforces.com/problemset/problem/598/D 分析:BFS,同一连通区域的周长一样,但查询过多会导致TLE,所以要将连通区域的答案储存,下次查询到该连通 ...
- 【Codeforces 598D】Igor In the Museum
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 同一个联通块里面答案都一样. 把每个联通块的答案都算出来 然后赋值就好 [代码] #include <bits/stdc++.h> ...
- Educational Codeforces Round 1(D. Igor In the Museum) (BFS+离线访问)
题目链接:http://codeforces.com/problemset/problem/598/D 题意是 给你一张行为n宽为m的图 k个询问点 ,求每个寻问点所在的封闭的一个上下左右连接的块所能 ...
- Codeforces 376A. Night at the Museum
A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- JVM调优总结(六)-分代垃圾回收详述2
分代垃圾回收流程示意 选择合适的垃圾收集算法 串行收集器 用单线程处理所有垃圾回收工作,因为无需多线程交互,所以效率比较高.但是,也无法使用多处理器的优势,所以此收集器适合单处理器机器.当然,此收集器 ...
- Windows Azure 安全最佳实践 - 第 7 部分:提示、工具和编码最佳实践
在撰写这一系列文章的过程中,我总结出了很多最佳实践.在这篇文章中,我介绍了在保护您的WindowsAzure应用程序时需要考虑的更多事项. 下面是一些工具和编码提示与最佳实践: · 在操作系统上运行 ...
- docker 学习手冊-中文版下载
这个PDF算是学习docker的一个小总结,全部文章摘自我在csdn的博客专栏: http://blog.csdn.net/column/details/docker.html 第一章到第八章摘自do ...
- 更改ORACLE 用户的 expired状态
oracle中, 经常用户的状态会变成locked, expired 等状态, 这种情况下怎么处理呢? 首先, 如果是locked状态还好办, DBA直接执行alter user scott acco ...
- javascript笔记整理(概述,变量,数据类型)
A.概述 1.输出工具: document.write()---可以是html alert()---字符串 prompt(text,defaultText) text---可选.要在对话框中显示的纯文 ...
- 查询mysql哪些表正在被锁状态
1.查进程,主要是查找被锁表的那个进程的ID SHOW PROCESSLIST; 2.kill掉锁表的进程ID KILL 10866;//后面的数字即时进程的ID
- 用c++开发基于tcp协议的文件上传功能
用c++开发基于tcp协议的文件上传功能 2005我正在一家游戏公司做程序员,当时一直在看<Windows网络编程> 这本书,把里面提到的每种IO模型都试了一次,强烈推荐学习网络编程的同学 ...
- C++操作符的优先级
C++操作符的优先级 C++操作符的优先级 操作符及其结合性 功能 用法 L L L :: :: :: 全局作用域 类作用域 名字空间作用域 ::name class::name namespace: ...
- 老斜两宗事-七层代理模式还是IP层VPN
1.七层代理模式还是IP层VPN 非常多人会问,我究竟是使用代理模式呢,还是使用VPN模式,假设我想数据在中间不安全的链路上实现加密保护的话.这个问题有一个背景.那就是,你想保护你的数据,能够使用VP ...
- 引用iscroll的一个封装方法
var Page = function(cid, data,callback) { var _self = this; var cid = $(cid); var currPage=1; // 下拉上 ...