[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
【问题描述】
给定一个字母矩阵,定义一个LQ三角形为某行中连续的几个字母、某列中连续的几个字母和一条45度的斜线中连续的几个字母组成的等腰直角三角形的边缘部分,其中每条边上的字母数量相等且至少为2
。
例如,对于下面的字母矩阵中,所有的字母 L 组成一个LQ三角形,所有字母 Q 组成了一个 LQ 三角形,所有字母 C 也组成了一个 LQ 三角形。
AAAAAAA ALLLLLA ALQQLAA ALQLAAC ALLAACC ALAACCC
如果一个 LQ 三角形边上的所有字母相等,则称为一个全相等三角形。以三个例子都是全相等三角形。
给定一个字母矩阵,请求其中有多少个全相等三角形。
【输入格式】
输入第一行包含两个整数 n, m,分别表示字母矩阵的行数和列数。
接下来 n 行,每行 m 个大写字母,为给定的矩阵。
【输出格式】
输出一行,包含一个整数,表示答案。
【样例输入】
3 4 AAAA ALAQ ALQQ
【样例输出】
4
【样例输入】
6 7 AAAAAAA ALLLLLA ALQQLAA ALQLAAC ALLAACC ALAACCC
【样例输出】
23
题解:枚举
#include <bits/stdc++.h> using namespace std; const int N = 15; int n, m; int
len; int ans = 0; string a[N]; bool check(int i, int j, int di, int dj) { char c
= a[i][j]; for(int k = 0; k < len - 1; k++) { i += di; j += dj; if(i < 0 || i >=
n|| j < 0 || j >= m) return false; if(c != a[i][j]) return false; } return true
; } int main() { cin >> n >> m; for(int i = 0; i < n; i++) { cin >> a[i]; } for(
len= min(n, m); len >= 2; len--) { for(int i = 0; i < n; i++) { for(int j = 0; j
< m; j++) { ans += (check(i, j, 1, 0) && check(i, j, 0, 1) && check(i + len - 1,
j, -1, 1)); ans += (check(i, j, 1, 0) && check(i, j, 0, -1) && check(i + len -
1, j, -1, -1)); ans += (check(i, j, -1, 0) && check(i, j, 0, 1) && check(i - len
+ 1, j, 1, 1)); ans += (check(i, j, -1, 0) && check(i, j, 0, -1) && check(i -
len+ 1, j, 1, -1)); } } } cout << ans << endl; return 0; }