```cpp
代码贴这里
```
`是英文模式中点1左边那个键
by 御坂13558号 @ 2019-01-05 18:45:19
希望更丰富的展现?[使用Markdown](https://www.luogu.org/wiki/show?name=%E5%B8%AE%E5%8A%A9%EF%BC%9Amarkdown)
by 豌豆射手皮0608 @ 2019-01-05 18:46:17
用下markdown
by 哔哩哔哩 @ 2019-01-05 18:47:45
希望更丰富的展现?使用Markdown
by All_Might @ 2019-01-05 18:52:15
希望更丰富的展现?使用Markdown
by without_wings @ 2019-01-05 19:39:51
希望更丰富的展现?使用Markdown
by Liveddd @ 2019-01-05 19:44:58
```include<iostream>
include<iomanip>
include<cstdio>
include<cstring>
include<cmath>
include<cstdlib>
include<algorithm>
include<map>
include<queue>
include<vector>
include<string>
using namespace std; inline int read(){ char ch=getchar();int x=0,f=1; while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x10+ch-'0';ch=getchar();}return xf; } int n,m; int ans; int mapn[1005][1005]; int ax[4]={-1,0,1,0}; int ay[4]={0,-1,0,1}; bool vis[1005][1005]; void dfs(int x,int y){ if(x<1||y<1||x>n||y>n)return; ans++;vis[x][y]=true; for(int i=0;i<=3;i++){ if(vis[x+ax[i]][y+ay[i]]==false&&mapn[x+ax[i]][y+ay[i]]!=mapn[x][y]){dfs(x+ax[i],y+ay[i]); }
}
return;
} void allzero(){ ans=0; for(int i=1;i<=n;i++){ for(int j=0;j<=n+1;j++){ vis[i][j]=false; } } for(int i=0;i<=n+1;i++){ vis[i][0]=true; vis[0][i]=true; vis[i][n+1]=true; vis[n+1][i]=true; } } int main(){ memset(mapn,0,sizeof(mapn)); n=read(); m=read(); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ char ch=getchar(); if(ch=='1')mapn[i][j]=1; else mapn[i][j]=0; } } for(int i=1;i<=m;i++){ allzero(); int a;int b; a=read(); b=read(); dfs(a,b); cout<<ans; } return 0; }```
by 幻影学霸刘 @ 2019-01-05 19:46:51
已无法拯救了
by 幻影学霸刘 @ 2019-01-05 19:47:11
懒得修TA的代码了
by TRZ_2007 @ 2019-01-05 19:48:40
@[冰卿](/space/show?uid=36324) 宽搜预处理整张图,查询O(1),怎么预处理自己思考吧,一个块内的答案是一样的
by runtime_error @ 2019-01-05 19:53:39