POJ 1873 (Enumerate all States + convex hull)

Source: Internet
Author: User
Tags chop

The fortified Forest
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 6115 Accepted: 1720

Description

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 he ancestors on their travels. To protect he trees from thieves, the king ordered that a high fence be built around them. His wizard is put in charge of the operation.
Alas, the wizard quickly noticed, the only suitable material available to build the fence is the wood from the trees themselves. In other words, it is necessary to cut-some trees in order to build a fence around the remaining trees. Of course, to prevent he head from being chopped off, the wizard wanted to minimize the value of the trees that had to be Cut. The wizard went to its tower and stayed there until he had found the best possible solution to the problem. The fence is then built and everyone lived happily ever after.

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

Input

The input contains several test cases, each of the which describes a hypothetical forest. Each test case is begins with a line containing a single integer n, 2 <= n <=, and the number of trees in the forest. The trees is identified by consecutive integers 1 to n. Each of the subsequent n lines contains 4 integers xi, Yi, vi, Li, and describe a single tree. (xi, Yi) is the position of the tree in the plane, VI was its value, and Li is the length of fence so can be built using The wood of the tree. VI and Li are between 0 and 10,000.
The input ends with a 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 E Nclosed 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 has 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 exc ESS Fencing (accurate to 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  3  0  2 5  5 20 25 7-3 30 320

Sample Output

Forest 1Cut these trees:2 4 5 Extra wood:3.16forest 2Cut these trees:2 Extra wood:15.00
Test instructions: The King has some trees, he wants to cut off some trees to fence around the rest of the tree, each tree has coordinates, values and a fence length, we should make the cut down the value of the tree as small as possible and the fence can be made to surround the remaining trees, if the value of the same option to cut down the quantity
Less, the number of the final output of the cut tree and the fence around the amount of left to remain.
Puzzle: Deep Pit ah ... WA several times, unexpectedly is the function name of the variable p[0] in the CMP function conflict ... World final water problem is very difficult. , but the idea is not difficult. Is each enumeration of those trees do not fetch and fetch, not more than 2^15, in binary notation. Then the convex hull. Comparison..
#include <iostream>#include<cstdio>#include<cstring>#include<math.h>#include<algorithm>#include<stdlib.h>using namespacestd;Const DoubleEPS = 1e-8;Const intN = -;structpoint{DoubleX,y,value,len;} P[n],q[n]; Point Stack[n];intN;DoubleCross (Point A,point b,point c) {return(a.x-c.x) * (B.Y-C.Y)-(A.Y-C.Y) * (b.x-c.x);}DoubleDis (point a,point b) {returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y));} Point Po; //Tai HangintCMP (point A,point b) {if(Cross (A,B,PO) >0)return 1; if(Cross (a,b,po) = =0&&dis (B,PO)-dis (A,PO) >eps)return 1; return 0;}DoubleGraham (Point p[),intN) {    if(n==0|| n==1)return 0; if(n==2)return 2*dis (p[0],p[1]); intK =0;  for(intI=0; i<n; i++)    {        if(p[k].y>p[i].y| | ((P[K].Y==P[I].Y) && (p[k].x>p[i].x))) k=i; } Swap (p[0],p[k]); PO= p[0];///Well, here    inttop=2; Sort (P+1, p+n,cmp); stack[0]=p[0]; stack[1]=p[1]; stack[2]=p[2];  for(intI=3; i<n; i++)    {         while(top>=1&&cross (p[i],stack[top],stack[top-1]) >=0) {Top--; } stack[++top]=P[i]; }    DoubleAns =0;  for(intI=1; i<=top; i++) {ans+=dis (stack[i],stack[i-1]); } ans+=dis (stack[top],stack[0]); returnans;}intMain () {int_count =1;  while(SCANF ("%d", &n)!=eof&&N) { for(intI=0; i<n; i++) {scanf ("%LF%LF%LF%LF",&p[i].x,&p[i].y,&p[i].value,&P[i].len); }        intT = (1<<n)-1; intCnt[n],id[n];///Save the number of the tree you want to cut off        DoubleSave=0; intnum=999999999;///The number of the number to cut off        DoubleMi=999999999;///Save the minimum value of the tree to be cut off         for(intI=1; i<t; i++)///1 means cut off the tree, 0 means not to chop, at least to chop a tree        {            DoubleValue=0, len=0; intk=0, k1=0;  for(intj=0; j<n; J + +)            {                if((I&GT;&GT;J) &1)///shift operation, indicating that the current j+1 tree is to be chopped off{cnt[k++] =J; Value+=P[j].value; Len+=P[j].len; }                Elseq[k1++] =P[j]; }            DoubleL =Graham (Q,K1); if(len-l>eps)///if the length of the fence can be larger than the convex Bao Zhouchang            {                if(mi-value>eps| | (Fabs (VALUE-MI) <eps&&k<num)) {mi=value;  for(intj=0; j<k; J + +) id[j]=Cnt[j]; Num=K; Save= Len-L; }}} printf ("Forest%d\ncut These trees:", _count++);  for(intI=0; i<num; i++) {printf ("%d", id[i]+1); } printf ("\nextra Wood:%.2lf\n\n", save); }    return 0;}

POJ 1873 (Enumerate all States + convex hull)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.