P1378 Oil Droplet expansion (backtracking, enumeration)
Title DescriptionIn a rectangular frame, a maximum of N (0≤n≤6) of different points, at any one of the points placed a very small oil droplets, then the oil droplets will continue to expand until exposed to other oil droplets or frame boundaries. You must wait for an oil droplet to expand before you can place the next drop of oil. Then, in what order should the oil droplets be placed on these n points, in order to make all the oil droplets occupy the overall product maximum. (different oil droplets do not fuse with each other)
Note: The Circle area Formula V=pi*r*r, where r is the radius of the circle.
input/output format
Input Format:Line 1th an integer n.
2nd Behavior Rectangle Border The coordinates of a vertex and its diagonal vertices, x,y,x ', y '.
Next n rows, two integers per line, xi,yi, representing the coordinates of the box's n points.
All of the above data is within [ -1000,1000].
output Format:A row, an integer, the smallest space remaining in a rectangular box (results rounded out)
input/Output sample
Input Sample:2
20 0 10 10
13 3
17 7
Sample output:50
Analysis of Problem solvingThe order in which the oil droplets are placed may result in different results.
The backtracking method is used to get all the different permutations of 1 to N, and then enumerates the order in which each permutation is placed, and gets the maximum area of the circle obtained in each way.
Note: To determine whether the center of an oil droplet is inside the circle formed by another placed oil droplet, if so, its radius is 0.
#include
#include
#include #include #include #include #include
using namespace Std;
#define PI 3.1415926
struct point{
int x;
int y;
} E[8], ret[2];
int n, a[8];
Double d[8][8], ans=0;
Double S (double R) {
return pi*r*r;
}
Double dis (point p1, point p2) {
double dx = p1.x-p2.x, dy = p1.y-p2.y;
return sqrt (DX*DX + dy*dy);
}
void Ini () {
int i, J;
for (I=1; ir1[j1])
r = min (r, D[i1][j1]-r1[j1]);
else
r = 0;
}
R1[I1] = r;
Ans1 + = s (r);
}
if (ANSN) {
solve ();
return;
}
for (i=depth; i<=n; i++) {
swap (a[depth], a[i]);
DFS (depth+1);
Swap (a[depth], a[i]);
}
}
int main () {
ios::sync_with_stdio (false);
int i, x, y, cnt = 1;
cin>>n;
cin>>ret[0].x>>ret[0].y>>ret[1].x>>ret[1].y;
for (I=1; i<=n; i++) {
cin>>e[i].x>>e[i].y;
A[i] = i;
}
INI ();
DFS (1);
cout<< (int) (ABS ((ret[0].x-ret[1].x) * (RET[0].Y-RET[1].Y))-ans + 0.5) <