题目链接: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的更多相关文章

  1. 【CodeForces - 598D】Igor In the Museum(bfs)

    Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...

  2. 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 ...

  3. 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 ...

  4. [BFS]Codeforces Igor In the Museum

     Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. 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 ...

  6. Codeforces 598D (ccpc-wannafly camp day1) Igor In the Museum

    http://codeforces.com/problemset/problem/598/D 分析:BFS,同一连通区域的周长一样,但查询过多会导致TLE,所以要将连通区域的答案储存,下次查询到该连通 ...

  7. 【Codeforces 598D】Igor In the Museum

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 同一个联通块里面答案都一样. 把每个联通块的答案都算出来 然后赋值就好 [代码] #include <bits/stdc++.h> ...

  8. Educational Codeforces Round 1(D. Igor In the Museum) (BFS+离线访问)

    题目链接:http://codeforces.com/problemset/problem/598/D 题意是 给你一张行为n宽为m的图 k个询问点 ,求每个寻问点所在的封闭的一个上下左右连接的块所能 ...

  9. 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 ...

随机推荐

  1. 利用navicat for oracle将数据库全部数据移动

    话不多说.直接上图. 1.首先选择自己的数据库. 右键,data transfer 2.选择相应源数据库,目标数据库.点击start就可以.假设中间失败,可多尝试几次. 2.

  2. 新书:《Liferay Portal 6.1最佳实践门户网站建设》

    新书:<Liferay Portal 6.1最佳实践门户网站建设>   <Liferay Portal 6.1门户站点建设最佳实践>是国内第一本全面介绍Liferay Port ...

  3. wireshark 抓包分析 TCPIP协议的握手

    wireshark 抓包分析 TCPIP协议的握手 原网址:http://www.cnblogs.com/TankXiao/archive/2012/10/10/2711777.html 之前写过一篇 ...

  4. 学习笔记(10) : Socket 编程典型代码积累

    网络编程实现的机制:   服务器端: 申请一个socket 绑定到一个IP地址和端口上 开启侦听,等待接受连接   客户端: 申请一个socket 连接服务器(指明IP.端口)   服务器端: 接收到 ...

  5. asp.net导出Excel类库

    using System; using System.Collections.Generic; using System.Reflection; using System.Web; using Exc ...

  6. Java7新特性(一)Coin

    1.语法糖 数字下划线   2.switch语句中的String   3.multicatch   4.final重抛 对比上份代码   5.try-with-resources(TWR) AutoC ...

  7. 【Android】属性动画

    转载请注明出处:http://blog.csdn.net/h28496/44338669 属性动画的原理 通过不断的设置一个View的属性让其出现动画效果.比如,不断地设置一个Button的x值.这个 ...

  8. 不包含SDK头文件, 补全API定义

    /// @file main.cpp /// @brief 不包含SDK头文件, 补全API定义 #ifdef __cplusplus extern "C" { #endif /* ...

  9. Axure自动备份功能!让意外不在可怕!

    忘记保存了......... 电脑意外重启了............... 不小心删除了.......................... 每次做axure的时候,多有了太多的意外了! 萧何今天在微 ...

  10. Spring中的p标签(转)good

    Spring的p标签是基于XML Schema的配置方式,目的是为了简化配置方式. 在XML文件头部添加xmlns:p="http://www.springframework.org/sch ...