题目链接:https://acm.ecnu.edu.cn/contest/173/problem/B/#report9

Problem B B 、 小 花梨 的 三角形
时间限制:1000ms 空间限制:512MB
Description
小花梨现在有一个𝑜层三角形图(参考下图),第𝑗层有2𝑗 − 1个边长为1的等边三角形。
每个交点处存在一个字符,总共有𝑜 + 1层字符,第𝑗层有𝑗个字符。
小花梨用等边三角形三个顶点上的字符来表示这个三角形,两个等边三角形如果它们的三个
顶点字符相同(不区分顺序)则视为同一类等边三角形。小花梨想知道总共存在多少种不同类
别的等边三角形。
Input
第一行为正整数𝑜,表示三角形层数(1 ≤ 𝑜 ≤ 100)。
接下来𝑜 + 1行,第𝑗行输入𝑗个字符,表示第𝑗层的字符。(字符只包含小写字母"𝑏 − 𝑧")
Output
输出一个整数表示存在多少种不同类别的三角形
Example
Sample Input Sample Output
1
a
bc
1
2
a
bb
cac
3
3
a
aa
aaa
aaaa
1
Note

一:只存在顶点为(𝑏,𝑐,𝑑)的三角形
二:存在顶点为(𝑏,𝑐,𝑐) 、 (𝑏,𝑑,𝑑) 、 (𝑏,𝑐,𝑑)的3类不同的三角形
样例三:只存在顶点为(𝑏,𝑏,𝑏)的三角形

思路:

枚举行,枚举列,枚举边长,统计三个节点的字母,
排序后插入set中即可。
存在正的三角形,还存在倒立的三角形

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2) { ans = ans * a % MOD; } a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int *p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
string temp;
set<string> st;
int n;
string a[maxn];
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    gbtb;
    cin >> n;
    n++;
    repd(i, 1, n) {
        cin >> a[i];
    }
    repd(i, 1, n) {
        repd(j, 0, i - 1) {
            int x = i;
            int y = j;
            for (int len = 1;; len++) {
                temp = "";
                if (x + len > n) {
                    break;
                }
                temp.pb(a[x][y]);
                temp.pb(a[x + len][y]);
                temp.pb(a[x + len][y + len]);
                sort(ALL(temp));
                st.insert(temp);
            }
        }
    }
    for (int i = n; i >= 1; --i) {
        repd(j, 0, i - 1) {
            int x = i;
            int y = j;
            for (int len = 1;; len++) {
                temp = "";
                if (x - len < 0 || y - len < 0 || y >= x - len ) {
                    break;
                }
                temp.pb(a[x][y]);
                temp.pb(a[x - len][y]);
                temp.pb(a[x - len][y - len]);
                sort(ALL(temp));
                st.insert(temp);
            }
        }

    }
    cout << sz(st) << endl;
    return 0;
}

inline void getInt(int *p)
{
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    } else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}