#include<bits/stdc++.h> usingnamespace std; bool Map[1005][1005]; int mapBooker[1005][1005]; int n,m; intsearch(int x,int y,bool last){ /*判定是否越界、已经搜索过*/ if(last==Map[x][y] or x<1or x>n or y<1or y>n or !mapBooker[x][y])return0; mapBooker[x][y]=1;//标记 returnsearch(x-1,y,id,Map[x][y])+search(x+1,y,id,Map[x][y])+search(x,y+1,id,Map[x][y])+search(x,y-1,id,Map[x][y])+1;//继续搜索,搜索周围四个点,同时算上自己
#include<bits/stdc++.h> usingnamespace std; bool Map[1005][1005]; int mapBooker[1005][1005]; int answerQueue[100005]; int n,m; intsearch(int x,int y,int id,bool last){ /*判定是否越界、已经搜索过*/ if(last==Map[x][y] or x<1or x>n or y<1or y>n or mapBooker[x][y]!=-1)return0; mapBooker[x][y]=id;//标记联通块编号 return answerQueue[id]=search(x-1,y,id,Map[x][y])+search(x+1,y,id,Map[x][y])+search(x,y+1,id,Map[x][y])+search(x,y-1,id,Map[x][y])+1;//搜索,同时将答案放入答案区