【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子列的个数; 然后让你输出 ...
随机推荐
- VS快捷键整理
Ctrl+J 自动提示Ctrl+. 解析ctrl+e,d 格式化代码ctrl+e,s 辅助横线Ctrl+m,o 全部合闭Ctrl+m,l 全部打开Ctrl + Shift + space 方法提示调用 ...
- ASP.NET给前端动态添加修改 CSS样式JS 标题 关键字(转载)
原文地址:http://www.cnblogs.com/xbhp/p/6392225.html 有很多网站读者能换自己喜欢的样式,还有一些网站想多站点共享后端代码而只动前段样式,可以采用动态替换CSS ...
- [Swift]经典解题思路:联合查找Union Find
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- gitlab&Jenkins 详细介绍及其应用
第1章 gitlab 1.1 系统环境 [root@jenkins ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) ...
- PowerDesigner 的使用教程
PowerDesigner 的使用这两篇博客挺好,我也是跟着学习,就不再写了: 初步学习: http://www.cnblogs.com/huangcong/archive/2010/06/14/17 ...
- 递推DP HDOJ 5375 Gray code
题目传送门 /* 题意:给一个串,只能是0,1,?(0/1).计算格雷码方法:当前值与前一个值异或,若为1,可以累加a[i],问最大累加值 DP:dp[i][0/1]表示当前第i位选择0/1时的最大分 ...
- Spring: (一) -- 春雨润物之 核心IOC
作为一个Java人,想必都或多或少的了解过Spring.对于其优势也能道个一二,诸如方便解耦.支持AOP编程.支持声明式事务.方便测试等等.Spring也不仅仅局限于服务器端开发,它可以做非常多的事情 ...
- idea安装插件plugin(主要针对网络连接不上的情况)
https://blog.csdn.net/duoduo1636546/article/details/80104711
- Dota2团战实力蔑视人类,解剖5只“AI英雄”
去年,OpenAI 在 DOTA 的 1v1 比赛中战胜了职业玩家 Dendi,而在距离进阶版 OpenAI Five 系统战胜人类业余玩家不过一个月的时间,今天凌晨,它又以 2:1 的战绩再次完成对 ...
- Git——基本操作
Shell 基本概念 shell俗称壳,为使用者提供使用界面,例如DOS下command以及后来的cmd.exe shell分类 图形界面shell,提供友好的可视化界面,例如windows操作界面, ...