油滴扩展10pts求调
  • 板块学术版
  • 楼主Stevehim
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/11/4 10:20
  • 上次更新2023/11/4 11:36:50
查看原帖
油滴扩展10pts求调
759274
Stevehim楼主2023/11/4 10:20

原题链接

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
double sq[7]; // 当前点上圆的半径
int vis[7]; //当前点是否存在油滴或者被油滴覆盖
double dis[7][7]; //点和点之间的距离
int n;
int x, y, xx, yy;
pii a[7];
double mi_dis[7]; //每个点x, y到边界的最短距离
double diss(int x, int y,int xx,int yy){
    return sqrt(abs(x -xx) * abs(x -xx) + abs(y - yy) * abs(y - yy));
}

double circ(double r){
    return r * r * 3.1415;
}

double ans = 0;
void dfs(int now,double sum,int cnt){
    //先检测
    if(cnt == n){
        ans = max(ans, sum);
        return;
    }
    //然后搜索
    for(int i = 1 ; i <= n; i++){
        //判断
        if(!vis[i]){
            //开始扩展
            double mi = mi_dis[i];
            for(int j = 1; j <= n; j++)
                if(vis[j] == 1) //某个油滴重心
                    mi = min(mi, dis[i][j] - sq[j]);
            //找出半径后开始扩展
            for(int j = 1; j <= n; j++)
                if(!vis[j] && dis[i][j] <= mi) //该点会被覆盖
                    vis[j] = 2;
            sq[i] = mi;
            vis[i] = 1;
            dfs(i, sum + circ(mi), cnt + 1);
            //开始还原
            vis[i] = 0;
            sq[i] = 0;
            for(int j = 1; j <= n; j++)
                if(!vis[j] && dis[i][j] <= mi)
                    vis[j] = 0;
        }
    }
}


int xa,xb,ya,yb;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    cin >> x >> y >> xx >> yy;
    x += 1000, y += 1000;
    xx += 1000, yy += 1000;
    for(int i = 1; i <= n; i++){
        cin >> a[i].first >> a[i].second;
        a[i].first += 1000, a[i].second += 1000;
    }
    for(int i = 1;  i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(i == j) continue;
            dis[i][j] = diss(a[i].first, a[i].second, a[j].first, a[j].second);
        }
    }
    for(int i = 1; i <= n; i++)
        mi_dis[i] = min(min(abs(a[i].first - x),abs(a[i].first - xx)), min(abs(a[i].second - y), abs(a[i].second - yy))); //计算边界
    dfs(0, 0, 0);
    cout << round(ans);
    return 0;
}
2023/11/4 10:20
加载中...