1 条题解

  • 0
    @ 2023-3-25 17:22:14

    暴力枚举滴油的顺序,模拟即可。

    时间复杂度 O(n!×n)\mathcal{O}(n!\times n)

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 10, nk[] = {0, 1, 2, 6, 24, 120, 720};
    int x[N], y[N], perm[N], n, x1, y_1, x2, y2;
    double ans, r[N];
    double dis(int u, int v) {
    	return sqrt((x[u] - x[v]) * (x[u] - x[v]) + (y[u] - y[v]) * (y[u] - y[v]));
    }
    int main() {
    	cin >> n >> x1 >> y_1 >> x2 >> y2;
    	ans = abs(x1 - x2) * abs(y_1 - y2);
    	for (int i = 1; i <= n; i ++)
    		cin >> x[i] >> y[i], perm[i] = i;
    	for (int i = 1; i <= nk[n]; i ++) {
    		double sum = abs(x1 - x2) * abs(y_1 - y2);
    		for (int j = 1; j <= n; j ++) {
    			double R = min(min(abs(x[perm[j]] - x1), abs(x[perm[j]] - x2)), min(abs(y[perm[j]] - y_1), abs(y[perm[j]] - y2)));
    			for (int k = 1; k < j; k ++)
    				R = min(R, max(dis(perm[j], perm[k]) - r[perm[k]], 0.0));
    			r[perm[j]] = R, sum -= R * R * 3.1415926;
    		}
    		ans = min(ans, sum), next_permutation(perm + 1, perm + 1 + n);
    	}
    	printf("%.0lf", ans);
    	return 0;
    }
    
    • 1

    信息

    ID
    394
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    (无)
    递交数
    57
    已通过
    28
    上传者