考察知识点:数学

斜率为 11 的直线通式为 y=x+by=x+b,斜率为 1-1 的直线通式为 y=x+by=-x+b

因此我们可以通过截距 b=yxb=y-xb=y+xb=y+x 来确定直线并统计点的个数。

两条直线可能有交点被统计,最后要注意去重。

时间复杂度O(n2)O(n^2)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define N 1005

void solve()
{
    int n, cnt = 0, x[N], y[N];
    cin >> n;
    map<int, set<int>> mp[2];
    for (int i = 0; i < n; i++)
        cin >> x[i];
    for (int i = 0; i < n; i++)
        cin >> y[i];
    for (int i = 0; i < n; i++)
    {
        mp[0][x[i] + y[i]].insert(cnt);
        mp[1][x[i] - y[i]].insert(cnt++);
    }
    int ans = 0;
    for (auto &i : mp[0])
        for (auto &j : mp[1])
        {
            int tmp = i.second.size() + j.second.size();
            for (auto &k : i.second)
                if (j.second.count(k))
                    tmp--;
            ans = max(ans, tmp);
        }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}