【Codeforces 598D】Igor In the Museum
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
同一个联通块里面答案都一样。
把每个联通块的答案都算出来 然后赋值就好
【代码】
#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的更多相关文章
- 【CodeForces - 598D】Igor In the Museum(bfs)
Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...
- 【codeforces 793B】Igor and his way to work
[题目链接]:http://codeforces.com/contest/793/problem/B [题意] 给一个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 ...
- 【87.65%】【codeforces 731A】Night at the Museum
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【30.43%】【codeforces 746C】Tram
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
随机推荐
- vue 加载文件,省略后缀后的加载顺序
Vue使用import ... from ...来导入组件,库,变量等.而from后的来源可以是js,vue,json.这个是在webpack.base.conf.js中设置的: module.exp ...
- 说说Charles
本文来源 https://blog.csdn.net/Aaroun/article/details/79109917 今天,给大家做一次分享,主要面向移动端测试,介绍了我平时接口开发工作中用到的功能. ...
- 士兵杀敌 三 --- O( 1 ) 的时间复杂度 .
一看就是 十分简单的 题 , 然后上去开始无脑程序 超时~~~ 感觉时间复杂度 , 已经很低了 , 但是并没有什么卵用 . #include<stdio.h> #in ...
- 【js】为什么要使用react+redux
前端的浪潮一叠叠袭来,带走了jQuery,带走了backbone,带来了react,带来了redux,但是面对层出不穷的前端技术,我们应该何去何从呢?近一年来笔者的也发生了同样的变化,技术栈从.net ...
- 清理TIME_WAIT
cat >> /etc/sysctl.conf << EOFnet.ipv4.tcp_tw_reuse=1net.ipv4.tcp_tw_recycle=1net.ipv4.t ...
- 最短路 Codeforces Round #103 (Div. 2) D. Missile Silos
题目传送门 /* 最短路: 不仅扫描边,还要扫描点:点有两种情况,一种刚好在中点,即从u,v都一样,那么最后/2 还有一种是从u,v不一样,两种的距离都是l 模板错了,逗了好久:( */ #inclu ...
- Troubleshooting Guide for ORA-12541 TNS: No Listener
Server side checks (not platform specific): 1) Check the result on the server using tnsping to the ...
- 1393 0和1相等串 鸽笼原理 || 化简dp公式
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1393 正解一眼看出来的应该是鸽笼原理.记录每个位置的前缀和,就是dp[i ...
- Angular JS中自定义标签 属性绑定的解释
看到自定义标签的文档时,文档作者解释的能力实在太弱,也可能是本人太笨,一下绕不过来. 看了一个stackoverflow答案,才算明白,在此贴出翻译,以供大家参考. .csharpcode, .csh ...
- 两年,VMware又重回巅峰?
两年前,被公有云和容器打的焦头烂额的VMware一度被众多业界人士看衰,营收.股价双双下滑.然而,仅仅经过短短两年时间,VMware已经和AWS,IBM.微软.Rackspace等众多公有云厂商成为合 ...