91tps #2WA
  • 板块P1331 海战
  • 楼主_chx
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/1/13 13:48
  • 上次更新2024/1/13 16:07:38
查看原帖
91tps #2WA
1017504
_chx楼主2024/1/13 13:48
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
char a[1005][1005];
void sou(int x,int y){
	a[x][y]='.';
	if(a[x][y+1]=='#'){
		sou(x,y+1);
	}
	if(a[x+1][y]=='#'){
		sou(x+1,y);
	}
	if(a[x][y-1]=='#'){
		sou(x,y-1);
	}
	if(a[x-1][y]=='#'){
		sou(x-1,y);
	}
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if((a[i][j]=='#'&&a[i][j+1]=='#'&&a[i+1][j]=='#'&&a[i+1][j+1]=='.')||
			(a[i][j]=='#'&&a[i][j+1]=='#'&&a[i+1][j]=='.'&&a[i+1][j+1]=='#')||
			(a[i][j]=='#'&&a[i][j+1]=='.'&&a[i+1][j]=='#'&&a[i+1][j+1]=='#')||
			(a[i][j]=='.'&&a[i][j+1]=='#'&&a[i+1][j]=='#'&&a[i+1][j+1]=='#')){
				cout<<"Bad placement.";
				return 0;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(a[i][j]=='#'){
				sou(i,j);
				ans++;
			}
		}
	}
	cout<<"There are "<<ans<<" ships.";
	return 0;
} 
2024/1/13 13:48
加载中...