Once upon a time, in a faraway land, there lived a king. This king owned a small collection of rare and valuable trees, which had been gathered by his ancestors on their travels. To protect his trees from thieves, the king ordered that a high fence be built around them. His wizard was put in charge of the operation.
Alas, the wizard quickly noticed that the only suitable material available to build the fence was the wood from the trees themselves. In other words, it was necessary to cut down some trees in order to build a fence around the remaining trees. Of course, to prevent his head from being chopped off, the wizard wanted to minimize the value of the trees that had to be cut. The wizard went to his tower and stayed there until he had found the best possible solution to the problem. The fence was then built and everyone lived happily ever after.
You are to write a program that solves the problem the wizard faced.
Input
The input contains several test cases, each of which describes a hypothetical forest. Each test case begins with a line containing a single integer $n$, $2\le n\le 15$, the number of trees in the forest. The trees are identied by consecutive integers $1$ to $n$. Each of the subsequent lines contains $4$ integers $x_i,y_i,v_i,l_i$ that describe a single tree. $(x_i,y_i)$ is the position of the tree in the plane, $v_i$ is its value, and $l_i$ is the length of fence that can be built using the wood of the tree. $vi$ and $li$ are between $0$ and $10,000$.
The input ends with an empty test case (n= 0).
Output
For each test case, compute a subset of the trees such that, using the wood from that subset, the remaining trees can be enclosed in a single fence. Find the subset with minimum value. If more than one such minimum-value subset exists, choose one with the smallest number of trees. For simplicity, regard the trees as having zero diameter.
Display, as shown below, the test case numbers (1, 2, …), the identity of each tree to be cut, and the length of the excess fencing (accurate to two fractional digits).
int n; structPoint { double x, y; int v, l; int id; Point() {} Point(double a, double b) : x(a), y(b) {} booloperator<(const Point &b) const { if (x < b.x) return1; if (x > b.x) return0; return y < b.y; } booloperator==(const Point &b) const { if (x == b.x && y == b.y) return1; return0; } Point operator-(const Point &b) { return Point(x - b.x, y - b.y); } } p[maxn], stk[maxn], tmp[maxn]; typedef Point Vec;
intsgn(double x){ if (fabs(x) <= eps) return0; return x > 0 ? 1 : -1; }
doubledist(Point a, Point b){ returnsqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); }