Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<queue>
- using namespace std;
- char sea[510][510];
- bool visited[510][510];
- int n,m;
- typedef struct{
- int I;
- int J;
- }pos;
- int max(int a,int b){
- return (a > b ? a : b);
- }
- int dfs(int I,int J){
- pos move[4] = {{-1,0},{0,1},{1,0},{0,-1}};
- queue<pos> q;
- q.push({I,J});
- int count = 0;
- while(!q.empty()){
- int nowI = q.front().I;
- int nowJ = q.front().J;
- q.pop();
- if(!visited[nowI][nowJ]){
- visited[nowI][nowJ] = true;
- if(sea[nowI][nowJ] == '*'){
- count++;
- }
- for(int i=0;i<4;i++){
- int newI = nowI + move[i].I;
- int newJ = nowJ + move[i].J;
- if(newI < 0)newI = n-1;
- else if(newI >= n)newI = 0;
- if(newJ < 0)newJ = m-1;
- else if(newJ >= m)newJ = 0;
- if(sea[newI][newJ] != '#' && !visited[newI][newJ]){
- q.push({newI,newJ});
- }
- }
- }
- }
- return count;
- }
- int main()
- {
- scanf("%d %d",&n,&m);
- for(int i=0;i<n;i++){
- scanf("%s",sea[i]);
- }
- int maxa = 0;
- for(int i=0;i<n;i++){
- for(int j=0;j<m;j++){
- if(sea[i][j] != '#'){
- int cal = dfs(i,j);
- maxa = max(maxa,cal);
- }
- }
- }
- printf("%d",maxa);
- }
Advertisement
Add Comment
Please, Sign In to add comment