题目
代码(巨复杂,跑了我十几分钟)
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int N = 18e6;
#define x first
#define y second
typedef pair<int, int> PII;
int line;
PII p1[N];
PII p2[N];
vector<PII> points;
double cal(PII a, PII b)
{
return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + 1.0 * (a.y - b.y) * (a.y - b.y));
}
bool at(int i, PII p)
{
PII a = p1[i], b = p2[i];
double dis[3];
dis[0] = cal(p, a);
dis[1] = cal(p, b);
dis[2] = cal(a, b);
sort(dis, dis + 3);
return fabs(dis[0] + dis[1] - dis[2]) < eps;
}
bool check(PII a, PII b)
{
for (int i = 1; i <= line; i++)
{
if (at(i, a) && at(i, b))
return false;
}
return true;
}
int main()
{
for (int x = 0; x < 20; x++)
{
for (int y = 0; y < 21; y++)
{
points.push_back({x, y});
}
}
for (auto a : points)
{
for (auto b : points)
{
if (a.x != b.x || a.y != b.y)
{
if (check(a, b))
{
line++;
p1[line] = a;
p2[line] = b;
}
}
}
}
cout << line;
return 0;
}