【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子列的个数; 然后让你输出 ...
随机推荐
- POJ 1659 Frogs' Neighborhood (贪心)
题意:中文题. 析:贪心策略,先让邻居多的选,选的时候也尽量选邻居多的. 代码如下: #pragma comment(linker, "/STACK:1024000000,102400000 ...
- 源码阅读之LinkedList(JDK8)
inkedList概述 LinkedList是List和Deque接口的双向链表的实现.实现了所有可选列表操作,并允许包括null值. LinkedList既然是通过双向链表去实现的,那么它可以被当作 ...
- [Usaco2005 oct]Flying Right 飞行航班
Description 为了表示不能输给人类,农场的奶牛们决定成立一家航空公司.她们计划每天早晨,从密歇根湖湖岸的最北端飞向最南端,晚上从最南端飞往最北端.在旅途中,航空公司可以安排飞机停在某些机场. ...
- focus、click、blur、display、float、border、absolute、relative、fixed
onfocus:获取焦点,点击时,按着不放 onclick:点击松开之后,未点击其他处 onblur:点击松开之后,又点击其他处 display:block,none,inline block:单独占 ...
- php 报错如下:Notice: Trying to get property of non-object
参考文档如下解决: https://stackoverflow.com/questions/5891911/trying-to-get-property-of-non-object-in 问题如下: ...
- pyDes 实现 Python 版的 DES 对称加密/解密--转
https://my.oschina.net/leejun2005/blog/586451 手头有个 Java 版的 DES 加密/解密程序,最近想着将其 Python 重构下,方便后续脚本解析,捣鼓 ...
- Modbus消息帧
两种传输模式中(ASCII和RTU),传输设备以将Modbus消息转为有起点和终点的帧,这就允许接收的设备在消息起始处开始工作,读地址分配信息,判断哪一个设备被选中(广播方式则传给所以设备),判知何时 ...
- Jmeter接口测试---JDBC简单实践
我的环境:MySQL:mysql-5.6.24-win32 jdbc驱动:mysql-connector-java-5.1.22-bin.jar JMeter:apache-jmeter-2.13 1 ...
- 学习RFT之:TestObject.find方法的了解与使用
第一部分:了解TestObject.find 一.TestObject.find方法的作用 1.测试过程中动态的找到测试对象(控件.标签等),使我们的测试用例不再依赖RFT自带的对象地图(Object ...
- 数据库–Cobar分布式数据库集群MySQL中间件
运行环境: 主机1:Ubuntu14.04 Desktop + MySQL5.5 + JDK 1.7(HP Z400) 内网IP地址:192.168.137.8 NODE1:Ubuntu 13.04 ...