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 ...
随机推荐
- 设计模式(二)单件模式Singleton(创建型)
SINGLETON(单件)—对象创建型模式 几乎所有面向对象的程序中,总有一些类的对象需要是唯一的,例如,通过数据库句柄到数据库的连接是独占的.您希望在应用程序中共享数据库句柄,因为在保持连接打开或关 ...
- ViewPageAsImage
var ViewPageAsImage = function(target, label) { var setting = { min_height: 4, min_width: 4 ...
- CloudStack全局配置參数
參数 描写叙述 类型 默认值 account.cleanup.interval 清除用户账户所须要等待的时间(秒) 整数 86400 agent.lb.enabled If agent load ba ...
- 编译kernel:配置
韦东山Linux视频第1期_裸板_UBoot_文件系统_驱动初步\第10课第2节 内核启动流程分析之配置.WMV 下面以DM9000的配置为例: 在一个编译好的内核代码里,寻找CONFIG_DM900 ...
- WPF 自带Datagrid编辑后无法更新数据源的问题
原文 WPF 自带Datagrid编辑后无法更新数据源的问题 解决办法: 在列的绑定属性里加上UpdateSourceTrigger,示例XAML如下 <DataGrid Grid.Row=& ...
- mmc生产运输投资问题
本题目,有生产,运输和投资,由于能力不能满足需求, 要扩大生产规模.
- 略懂 MySQL字符集
本文虽说旨在明白.但若略懂亦可.毕竟诸葛孔明如是 只有基于字符的值才有所谓字符集的概念 某些字符集可能需要更多CPU.消费更多的内存和磁盘空间.甚至影响索引使用 这还不包括令人 ...
- DDD领域驱动设计的理解
DDD领域驱动设计的理解 从遇到问题开始 当人们要做一个软件系统时,一般总是因为遇到了什么问题,然后希望通过一个软件系统来解决. 比如,我是一家企业,然后我觉得我现在线下销售自己的产品还不够,我希望能 ...
- 同一个form里,不管哪个 submit 都是直接提交form表单里的内容
要达到你的目的,就不能用类型为 submit 的按钮,要用 button,然后加onclick 方法来自定义预处理参数,然后再调用 submit 方法提交表单,比如 <script type=& ...
- python web with bottle and session (beaker)
python web with bottle and session (beaker) http://icodesnip.com/snippet/python/python-web-with-bott ...