求助...
查看原帖
求助...
141599
sinsop90楼主2020/10/7 15:18

样例全过,提交爆零

啊啊啊改一道橙题改这么久窝菜死了

#include<bits/stdc++.h>
using namespace std;
int n,m,maxn=-1,ans;
char mps[1005][1005];
bool vis[1005][1005],flag;
int fx[4][2] = {0,1,0,-1,1,0,-1,0};
bool check(int xx,int yy){
	if(xx>=1 && xx<=n && yy>=1 && yy<=m && !vis[xx][yy] && mps[xx][yy]!='*') return true;
	return false;
}
bool dfs(int x,int y,int dep){
//	cout<<x<<" "<<y<<endl;
	maxn = max(dep,maxn);
	if(x==1 || x==n || y==1 || y==m){
		flag = false;
	}
	for(int i=0;i<=3;i++){
		int xx = x+fx[i][0];
		int yy = y+fx[i][1];
		if(check(xx,yy)){
			vis[xx][yy] = true;
			dfs(xx,yy,dep+1);
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>mps[i][j];
		}
	}
	for(int i=2;i<n;i++){
		for(int j=2;j<m;j++){
			if(!vis[i][j] && mps[i][j]!='*'){
				maxn = -1;
				flag = true;
				vis[i][j] = true;
				dfs(i,j,1);
				if(flag){
					ans+=maxn;
//					cout<<i<<" "<<j<<" "<<ans<<endl;
				}
			}
		}
	}
	cout<<ans<<endl;
}
2020/10/7 15:18
加载中...