# poj 1873 The Fortified Forest 搜索+凸包

### 代码：

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)
#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)
#define mes(a,x,s)  memset(a,x,(s)*sizeof a[0])
#define mem(a,x)  memset(a,x,sizeof a)
#define ysk(x)  (1<<(x))
#define sqr(x)  ((x)*(x))

typedef long long ll;
typedef pair<int, int> pii;
const int INF =0x3f3f3f3f;
const int maxn= 15    ;

const double PI=acos(-1.0);
const double eps=1e-10;
int dcmp(double x)
{
if(fabs(x)<eps)  return 0;
else return x<0?-1:1;
}
struct Point
{
double x,y;
int val,len,id;
Point(double x=0,double y=0):x(x),y(y) {};
bool operator ==(const Point B)const {return dcmp(x-B.x)==0&&dcmp(y-B.y)==0;}

bool operator<(const Point& b)const
{
return dcmp(x-b.x)<0|| dcmp(x-b.x)==0 &&dcmp(y-b.y)<0;
}
};
typedef Point Vector;
Vector operator -(Vector A,Vector B) {return Vector(A.x-B.x,A.y-B.y); }

double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}

double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}

Vector operator +(Vector A,Vector B) {return Vector(A.x+B.x,A.y+B.y); }
Vector operator *(Vector A,double p) {return Vector(A.x*p,A.y*p); }
Vector operator /(Vector A,double p) {return Vector(A.x/p,A.y/p); }
Vector operator -(Vector A)  {return  Vector(-A.x,-A.y);}

double dis(Point A,Point B)
{
return sqrt(sqr(A.x-B.x)+sqr(A.y-B.y));
}

Point po[maxn+10],chp[maxn+10];
bool use[maxn+4];
int n;
double ConvexHell(Point *p,int n,Point *ch,int rea)
{

int m=0;
for(int i=0;i<n;i++) if(use[i])
{
while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-1]   )<=0   )  m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-2;i>=0;i--) if(use[i])
{
while(m>k &&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-1] )<=0)   m--;
ch[m++]=p[i];
}
if(rea>1)  m--;
//    if(m<=1)  return 0;
//    if(m==2)  return dis(ch[0],ch[1]);
double D=0;
for0(i,m)
{
D+=dis(ch[i],ch[ (i+1)%m ]);
}
//    cout<<"Convex "<<m<<endl;
return D;

}

void solve()
{
int ed=ysk(n)-1;
int minVal=-1,num=-1,best=-1;
double extr=-1;
for0(s,ed+1)
{
int v=0,cnt=0,L=0;
for0(i,n)
{
if(s&ysk(i)) use[i]=1;
else  {use[i]=0;L+=po[i].len;v+=po[i].val,cnt++;}
}
double D=ConvexHell(po,n,chp,n-cnt);
//        cout<<s<<" "<<D<<endl;
if(dcmp(L-D)<0)  continue;
if(minVal<0||minVal>v||minVal==v&&num>cnt )  {minVal=v;num=cnt;best=s;extr=L-D;}

}
printf("Cut these trees:");
vector<int >ve;
for0(i,n) if( !(ysk(i)&best) ) ve.push_back(po[i].id+1);
sort(all(ve));
for0(i,ve.size())  printf(" %d",ve[i]);
putchar('\n');
printf("Extra wood: %.2f\n\n",extr);

}
int main()
{
std::ios::sync_with_stdio(false);
int kase=0;
while(cin>>n&&n)
{

for0(i,n) {cin>>po[i].x>>po[i].y>>po[i].val>>po[i].len;po[i].id=i;}
sort(po,po+n);
printf("Forest %d\n",++kase);
solve();
}
return 0;
}

#### poj 1873 The Fortified Forest（凸包）

2013-11-27 23:30:16

#### POJ 1873 The Fortified Forest（凸包）

2017-08-10 18:53:44

#### poj 1873 The Fortified Forest （凸包）

2017-01-02 15:21:53

#### poj 1873 The Fortified Forest(凸包)

2015-08-11 23:47:42

#### POJ 1873 The Fortified Forest 凸包+搜索

2012-12-19 17:01:18

#### POJ 1873 The Fortified Forest

2011-06-02 16:30:00

#### POJ - 1873 The Fortified Forest

2017-12-21 21:44:11

#### POJ 1873 The Fortified Forest

2013-08-20 23:28:41

#### poj 1873 The Fortified Forest

2016-08-24 16:20:54

#### poj - 1873 - The Fortified Forest

2013-07-24 04:14:52