【直线 / B】

题目

代码(巨复杂,跑了我十几分钟)

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值