#include"bits/stdc++.h"
#define int long long
using namespace std;
const int nx[4] = {0, 0, 1, -1};
const int ny[4] = {1, -1, 0, 0};
char mn[1100][1100];
int r, c, ans;
bool check(int x, int y){
int num = 0;
if(mn[x][y] == '#'){
cout << x << ' ' << y << endl;num ++;
}
if(mn[x][y + 1] == '#'){
cout << x << ' ' << y + 1 << endl;
num ++;
}
if(mn[x + 1][y] == '#'){
num ++;
cout << x + 1 << ' ' << y << endl;
}
if(mn[x + 1][y + 1] == '#'){
cout << x + 1 << ' ' << y + 1 << endl;
num ++;
}
cout << "---------------\n";
if(num == 3){
return 1;
}
else return 0;
}
void dfs(int x, int y){
if(mn[x][y] != '#') return ;
if(x < 0 || x > r || y < 0 || y > c) return ;
mn[x][y] = 'm';
for(int i = 0; i <= 3; i ++){
if(mn[x + nx[i]][y + ny[i]] == '#'){
dfs(x + nx[i], y + ny[i]);
}
}
}
signed main(){
scanf("%lld%lld", &r, &c);
for(int i = 1; i <= r; i ++){
for(int j = 1; j <= c; j ++){
scanf("%c", &mn[i][j]);
}
}
for(int i = 1; i < r; i ++){
for(int j = 1; j < c; j ++){
if(check(i, j)){
printf("Bad placement.");
return 0;
}
}
}
for(int i = 1; i <= r; i ++){
for(int j = 1; j <= c; j ++){
if(mn[i][j] == '#'){
ans ++;
dfs(i, j);
}
}
}
printf("There are %lld ships.", ans);
return 0;
}
样例错了,蒟蒻挑不出来
求助dalao, Orz玄关