【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

同一个联通块里面答案都一样。
把每个联通块的答案都算出来 然后赋值就好

【代码】

#include <bits/stdc++.h>
using namespace std;
const int N = 1000; int n,m,k;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
char s[N+10][N+10];
bool bo[N+10][N+10];
int ans[N+10][N+10];
pair<int,int> dl[N*N+10];
int head,tail; int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m >> k;
for (int i = 1;i <= n;i++) cin >> (s[i]+1);
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
if (!bo[i][j] && s[i][j]=='.'){
head = 1,tail = 1;
dl[head] = {i,j};
int cnt = 0;
bo[i][j] = true;
while (head<=tail){
int x = dl[head].first,y = dl[head].second;
head++;
for (int l = 0;l < 4;l++){
int tx = x + dx[l],ty = y + dy[l];
if (tx>=1 && tx <= n && ty>=1 && ty<=m){
if (!bo[tx][ty] && s[tx][ty]=='.'){
bo[tx][ty] = true;
tail++;
dl[tail].first = tx;
dl[tail].second = ty;
}else if (s[tx][ty]=='*'){
cnt++;
}
}
}
}
for (int i = 1;i <= tail;i++){
ans[dl[i].first][dl[i].second] = cnt;
}
}
for (int i = 1;i <= k;i++){
int x,y;
cin >> x >> y;
cout<<ans[x][y]<<endl;
}
return 0;
}

【Codeforces 598D】Igor In the Museum的更多相关文章

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

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

  2. 【codeforces 793B】Igor and his way to work

    [题目链接]:http://codeforces.com/contest/793/problem/B [题意] 给一个n*m大小的方格; 有一些方格可以走,一些不能走; 然后问你从起点到终点,能不能在 ...

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

  4. 【87.65%】【codeforces 731A】Night at the Museum

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  6. 【30.43%】【codeforces 746C】Tram

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  8. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  9. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

随机推荐

  1. UEditor动态添加图片访问路径前缀

    在使用UEditor上传图片时发现上传图片后在编辑器中不能显示上传的图片,在这里是需要在jsp/config.json中设置图片访问路径前缀,即项目的根路径,在config.json只能填写字符串的配 ...

  2. SQL Server 添加描述

    添加描述的格式 exec sys.sp_addextendedproperty @name = N'MS_Description' ,@value = 'value',@level0type=N'SC ...

  3. Objective-C 继承与类

    创建: 2018/01/20 完成: 2018/01/21 更新: 2018/01/22 标题前增加 [Objective-C]  继承的概念  父类与子类 ●继承: 继承其他类 ●父类: 被继承的类 ...

  4. bzoj 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏【Floyd】

    先跑一遍取max版的Floyd,直接用数组回答询问即可 #include<iostream> #include<cstdio> using namespace std; con ...

  5. [Swift通天遁地]一、超级工具-(9)在地图视图MKMapView中添加支持交互动作的标注图标

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. Classic BADI总结

    这里对sap Classic Badi 做一下总结,虽然已经是过时的技术了. Classic BADI的创建 Classic BADI的实施 Classic BADI的调用及运行原理 New BADI ...

  7. idea下载安装指南

    官网地址 https://www.jetbrains.com/idea/ 点击download 有收费版本和社区免费版.我下载了免费的. 有zip和exe两个版本.我先下载了zip绿色版,发现用不了. ...

  8. 2017杭电多校第六场1011Classes

    传送门 Classes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tota ...

  9. 395 Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子串

    找到给定字符串(由小写字符组成)中的最长子串 T , 要求 T 中的每一字符出现次数都不少于 k .输出 T 的长度.示例 1:输入:s = "aaabb", k = 3输出:3最 ...

  10. Python批量生成用户名

    写在最前 平时在工作中尤其是在做压测的时候难免需要一些用户名和密码,写个简单的Python小脚本批量生成一些 代码示例 import random,string #生成大小字母和数字一起的大字符串 a ...