10分求助
查看原帖
10分求助
553640
Konjac0629楼主2023/9/3 19:44

RT,大佬们帮忙看看出了什么问题

记录

#include <bits/stdc++.h>

using namespace std;

map<int, pair<int, int>> point;

map<int, bool> isExtended;

map<int, double> r;

int n, x_1, y_1, x_2, y_2;
double ans;

void dfs(int now, double sumS)
{
    if (now == n + 1)
    {
        ans = max(ans, sumS);
        return;
    }
    for (auto &k : point)
    {
        bool temp = false;
        if (isExtended[k.first] == false)
        {
            for (auto &q : point)
            {
                if (isExtended[q.first] == true && r[q.first] >= sqrt(pow((q.second.first - k.second.first), 2) + pow((q.second.second - k.second.second), 2)))
                {
                    temp = true;
                    isExtended[k.first] = true;
                    dfs(now + 1, sumS);
                    isExtended[k.first] = false;
                }
            }
            if (temp == true)
                continue;
            isExtended[k.first] = true;
            r[k.first] = min(min(fabs(x_1 - k.second.first), fabs(x_2 - k.second.first)), min(fabs(y_1 - k.second.second), fabs(y_2 - k.second.second)));
            for (auto &p : point)
            {
                if (k.first != p.first && isExtended[p.first])
                {
                    r[k.first] = min(r[k.first], sqrt(pow((k.second.first - p.second.first), 2) + pow((k.second.second - p.second.second), 2)) - r[p.first]);
                }
            }
            dfs(now + 1, sumS + pow(r[k.first], 2) * 3.14159265);
            r[k.first] = 0;
            isExtended[k.first] = false;
        }
    }
}

int main()
{
    cin >> n >> x_1 >> y_1 >> x_2 >> y_2;
    for (int i = 0; i < n; i++)
    {
        int xt, yt;
        cin >> xt >> yt;
        point[i] = {xt, yt};
    }
    dfs(1, 0.00);
    cout << round(ans) << endl;
    return 0;
}
2023/9/3 19:44
加载中...