思路解析:可以枚举顶点然后判等腰三角形
需要预存一下连续的‘*’有多少,以备判等腰三角形的时候用(不然会超时哦)
拿样例来说就像这样:
其中的非0数字就是其以及其左边连续的‘*’的个数
废话不多说,代码如下:
#include<bits/stdc++.h>
using namespace std;
#define int long long
using T = pair<int, int>;
//set<int>S;
//unordered_map<int, int>mp;
const int N = 2e5 + 10;
char a[501][501];
int left_num[501][501];
int n, m;
int ans(int x, int y) {
int i, cnt{ 2 }, j;
int res{};
for (i = x + 1; i <= n; ++i) {
if (y - cnt + 1 < 1 || y + cnt - 1 > m || a[i][y - cnt + 1] == '.' || a[i][y + cnt - 1] == '.')return res;
if (left_num[i][y + cnt - 1]>=2*cnt-1)++res;
++cnt;
}
return res;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
int i, j,k;
for (i = 1; i <= n; ++i) {
for (j = 1; j <= m; ++j) {
cin >> a[i][j];
if (a[i][j] == '*'){
left_num[i][j] = left_num[i][j - 1]+1;
}
}
}
int res{};
for (i = 1; i <= n; ++i) {
for (j = 1; j <= m; ++j) {
if (a[i][j] == '*')
res += ans(i, j);
//cout << left_num[i][j] << " ";
}//cout << endl;
}
cout << res;
return 0;
}