- 三子棋
暴力
- @ 2026-1-30 20:27:49
#include <bits/stdc++.h>
#define int long long
#define N 60
using namespace std;
int n,m;
char a[N][N];
int ans;
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i=3;i<=n+2;++i){
for (int j=3;j<=m+2;++j){
cin >> a[i][j];
}
}
for (int i=3;i<=n+2;++i){
for (int j=3;j<=m+2;++j){
if (a[i][j] == '#') continue;
// 竖
if(a[i+1][j] == '#' && a[i-1][j] == '#') ans++;
else if(a[i+1][j] == '#' && a[i+2][j] == '#') ans++;
else if(a[i-1][j] == '#' && a[i-2][j] == '#') ans++;
// 横
else if(a[i][j+1] == '#' && a[i][j-1] == '#') ans++;
else if(a[i][j+1] == '#' && a[i][j+2] == '#') ans++;
else if(a[i][j-1] == '#' && a[i][j-2] == '#') ans++;
//斜
else if(a[i+1][j+1] == '#' && a[i-1][j-1] == '#') ans++;
else if(a[i+1][j+1] == '#' && a[i+2][j+2] == '#') ans++;
else if(a[i-1][j-1] == '#' && a[i-2][j-2] == '#') ans++;
else if(a[i-1][j+1] == '#' && a[i+1][j-1] == '#') ans++;
else if(a[i-1][j+1] == '#' && a[i-2][j+2] == '#') ans++;
else if(a[i+2][j-2] == '#' && a[i+1][j-1] == '#') ans++;
}
}
cout << ans;
return 0;
}
0 comments
No comments so far...
Information
- ID
- 152
- Time
- ms
- Memory
- MiB
- Difficulty
- 1
- Tags
- # Submissions
- 58
- Accepted
- 24
- Uploaded By