You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
const int N = 110;
char a[N][N];
/*
4
abccddadca
2
aaa
*/
using namespace std;
struct Node {
int x, y;
char c;
};
vector<Node> q;
/*
把半径当做 1 ,建立坐标系,然后枚举就行了,需要注意的是,在判断三条边的长度是否相等时用 double 牵扯到精度问题,
解决方法是:比较长度的平方长度的平方肯定是整数还有就是层层之间纵坐标相差是sqrt(3) 的倍数,
为了不牵扯到小数,把纵坐标的 sqrt(3) 当做1 ,求边长时乘三即可。
*/
int pf(int x) {
return x * x;
}
bool check(Node a, Node b, Node c) {
if (a.c != b.c || a.c != c.c || b.c != c.c) return false;
// a与b之间距离 不等于 a与c之间距离
if (pf(a.x - b.x) + pf(a.y - b.y) * 3 != pf(a.x - c.x) + pf(a.y - c.y) * 3) return false;
// a与b之间距离 不等于 b与c之间距离
if (pf(a.x - b.x) + pf(a.y - b.y) * 3 != pf(b.x - c.x) + pf(b.y - c.y) * 3) return false;
return true;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("ZhiMuSanJiaoXing.in", "r", stdin);
#endif
int n;
cin >> n;
string s;
cin >> s;
// 先把字符串存入char[][]
int idx = 0;
for (int i = 0; i < n; i++) // n行
for (int j = 0; j <= i; j++) // i列
a[i][j] = s[idx++];
// 把所有坐标记录下来
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
q.push_back({n - 1 - i, j, a[i][j]});
// cout << "x=" << n - 1 - i << ",y=" << j << " " << a[i][j] << endl;
}
}
vector<char> res;
// 在q数组中选择任意三个计算两两间距离是不是相等
for (int i = 0; i < q.size(); i++)
for (int j = i + 1; j < q.size(); j++)
for (int k = j + 1; k < q.size(); k++) {
if (check(q[i], q[j], q[k])) res.push_back(q[i].c);
}
// if (res.size() == 0)
// cout << "No Solution" << endl;
// else {
// sort(res.begin(), res.end());
// for (char x : res) cout << x << endl;
// }
return 0;
}