#include<bits/stdc++.h>
using namespace std;
char mp[1010][1010];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int vis[1100][1100];
vector<pair<int,int> > v;
int n,m,k;
int flag=0;
void dfs(int x,int y)
{
if(vis[x][y])
{
return;
}
vis[x][y]=1;
v.push_back(make_pair(x,y));
// cout<<x<<" "<<y<<" "<<flag<<endl;
for(int i=0;i<4;i++)
{
int Dx = x+dx[i];
int Dy = y+dy[i];
if(Dx>=1&&Dx<=n&&Dy>=1&&Dy<=m&&mp[Dx][Dy]=='*')
{
flag++;
}else if(Dx>=1&&Dx<=n&&Dy>=1&&Dy<=m&&mp[Dx][Dy]=='.')
{
dfs(Dx,Dy);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>mp[i][j];
}
}
for(int i=1;i<=k;i++)
{
int x,y;
cin>>x>>y;
flag=0;
if(vis[x][y]!=0)
{
cout<<vis[x][y]<<endl;
continue;
}
v.clear();
dfs(x,y);
for(int i=0;i<v.size();i++)
{
vis[v[i].first][v[i].second]=flag;
}
cout<<vis[x][y]<<endl;
}
return 0;
}
D. Igor In the Museum
最新推荐文章于 2024-08-21 18:16:36 发布