PKU 1873 The Fortified Forest

来源:互联网 发布:网站建设免费域名 编辑:程序博客网 时间:2024/06/07 22:24

Description

Once upon atime, in a faraway land, there lived a king. This king owned a smallcollection of rare and valuable trees, which had been gathered by hisancestors on their travels. To protect his trees from thieves, the kingordered that a high fence be built around them. His wizard was put incharge of the operation.
Alas, the wizard quickly noticed that the only suitable materialavailable to build the fence was the wood from the trees themselves. Inother words, it was necessary to cut down some trees in order to builda fence around the remaining trees. Of course, to prevent his head frombeing chopped off, the wizard wanted to minimize the value of the treesthat had to be cut. The wizard went to his tower and stayed there untilhe had found the best possible solution to the problem. The fence wasthen built and everyone lived happily ever after.

You are to write a program that solves the problem the wizard faced.

Input

Theinput contains several test cases, each of which describes ahypothetical forest. Each test case begins with a line containing asingle integer n, 2 <= n <= 15, the number of trees in theforest. The trees are identified by consecutive integers 1 to n. Eachof the subsequent n lines contains 4 integers xi, yi, vi, li thatdescribe a single tree. (xi, yi) is the position of the tree in theplane, vi is its value, and li is the length of fence that can be builtusing 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

Foreach test case, compute a subset of the trees such that, using the woodfrom that subset, the remaining trees can be enclosed in a singlefence. Find the subset with minimum value. If more than one suchminimum-value subset exists, choose one with the smallest number oftrees. For simplicity, regard the trees as having zero diameter.
Display, as shown below, the test case numbers (1, 2, ...), theidentity of each tree to be cut, and the length of the excess fencing(accurate to two fractional digits).

Display a blank line between test cases.

Sample Input

6
0 0 8 3
1 4 3 2
2 1 7 1
4 1 2 3
3 5 4 6
2 3 9 8
3
3 0 10 2
5 5 20 25
7 -3 30 32
0

Sample Output

Forest 1
Cut these trees: 2 4 5
Extra wood: 3.16

Forest 2
Cut these trees: 2
Extra wood: 15.00

实际上,由于数据量比较小,所以代码写的比较随意,没有优化。基本思想是:用dfs求最佳解;判断解是否成立是,要用砍倒的长度和凸包周长进行对比,这里求凸包用了实现比较差的增量法,但是就是代码简单我有什么办法。