洛谷P1378

这道题需要处理的信息比较多,需要注意的是一个油滴扩展后可能会包含其他的点

#include <iostream>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
#define fi(i, a, b) for (int i = a; i <= b; ++i)
#define fr(i, a, b) for (int i = a; i >= b; --i)
#define x first
#define y second
#define sz(x) ((int)(x).size())
#define pb push_back
using pii = pair<int, int>;
vector<pair<int, int>> vec;
int up, down, lef, rig;
int full_a[6];
bool vis[6];
double dis[6][6];
double cir[6];
int n;
double maxx;
double ans;
//#define DEBUG
void dfs(int x)
{
    if (x == n)
    {
        ans = 0;
        fi(i, 0, n - 1)
        {
            if(cir[i] == -1)
                continue;
            else
                ans += pow(cir[i], 2);
        }
        ans = ans * M_PI;
        maxx = max(ans, maxx);
        return;
    }
    fi(i, 0, n - 1)
    {
        if (!vis[i])
        {
            vis[i] = true;
            full_a[x] = i;
            double p = min(abs(vec[i].x - lef), abs(vec[i].x - rig));
            double q = min(abs(vec[i].y - up), abs(vec[i].y - down));
            double minn = min(q, p);
            fi(j, 0, n - 1)
            {
                if (cir[j])
                {
                    minn = min(minn, dis[i][j] - cir[j]);
                }
            }
            if(minn < 0)
                cir[i] = -1;
            else
                cir[i] = minn;
            // cout << cir[i] << endl;
            dfs(x + 1);
            cir[i] = 0;
            vis[i] = false;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int temp = n;
    int x, y, x1, y1;
    cin >> x >> y >> x1 >> y1;
    up = y, down = y1, lef = x, rig = x1;
    while (temp--)
    {
        int a, b;
        cin >> a >> b;
        vec.push_back({a, b});
    }
    fi(i, 0, sz(vec) - 1) fi(j, i + 1, sz(vec) - 1)
    {
        dis[i][j] = dis[j][i] = sqrt(pow((vec[i].x - vec[j].x), 2) + pow((vec[i].y - vec[j].y), 2));
        // cout<< dis[i][j] << endl;
    }

    dfs(0);
    int cnt = abs(up - down) * abs(lef - rig);
    // cout << cnt << endl;
    cnt = cnt - maxx + 0.5;
    cout << cnt << endl;
#ifdef DEBUG
    //freopen(D:\in.txt,r,stdin);
#endif
    return 0;
}
posted @ 2022-01-28 11:23  Sun-Wind  阅读(26)  评论(0编辑  收藏  举报