/*
poj1873 The Fortified Forest 凸包+枚举 水题
用小树林的木头给小树林围一个围墙
每棵树都有价值
求消耗价值最低的做法,输出被砍伐的树的编号和剩余的木料
若砍伐价值相同,则取砍伐数小的方案。
*/
#include<stdio.h>
#include<math.h>
#include <algorithm>
#include <vector>
using namespace std;
const double eps = 1e-8;
struct point
{
double x,y;
};
struct exinfo
{
int v,l;
}info[20];
int n;
point dian[20],zhan[20];
//////////////////////////////////////////////////
point *mo_dian;
double mo_distance(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double mo_xmult(point p2,point p0,point p1)//p1在p2左返回负,在右边返回正
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} bool mo_ee(double x,double y)
{
double ret=x-y;
if(ret<0) ret=-ret;
if(ret<eps) return 1;
return 0;
}
bool mo_gg(double x,double y) { return x > y + eps;} // x > y
bool mo_ll(double x,double y) { return x < y - eps;} // x < y
bool mo_ge(double x,double y) { return x > y - eps;} // x >= y
bool mo_le(double x,double y) { return x < y + eps;} // x <= y bool mo_cmp(point a,point b) // 第一次排序
{
if( mo_ee(a.y ,b.y ) )
return mo_ll(a.x, b.x);
return mo_ll(a.y,b.y);
}
bool mo_cmp1(point a,point b) // 第二次排序
{
double len = mo_xmult(b,mo_dian[0],a);
if( mo_ee(len,0.0) )
return mo_ll(mo_distance(mo_dian[0],a),mo_distance(mo_dian[0],b));
return mo_gg(len,0.0);
}
int mo_graham(int n,point *dian,point *stk)
{
int i,top=1;
mo_dian=dian;
sort(mo_dian,mo_dian+n,mo_cmp);
sort(mo_dian+1,mo_dian+n,mo_cmp1);
stk[0]=mo_dian[0];
stk[1]=mo_dian[1];
for(i=2;i<n;++i)
{
while(top>0&&mo_xmult(mo_dian[i],stk[top-1],stk[top])<=0) --top;
stk[++top]=mo_dian[i];
}
return top+1;
} ////////
void getpoint(int tree,point *dian,point *work,vector<int> &cut,int &n_cut,int &n_sheng,int &cutv,int &cutl)
{
cut.clear();
cutv=0;
cutl=n_sheng=n_cut=0;
int i;
for(i=0;i<n;++i)
{
if((1<<i)&tree)//cut
{ cut.push_back(i);
n_cut++;
cutv+=info[i].v;
cutl+=info[i].l;
}else
{
work[n_sheng++]=dian[i];
}
}
}
double zhou(point *dian,int n)
{
int i;
double ret=0;
for(i=0;i<n;++i)
{
ret+=sqrt(
(dian[(i+1)%n].x-dian[i].x)*(dian[(i+1)%n].x-dian[i].x)
+(dian[(i+1)%n].y-dian[i].y)*(dian[(i+1)%n].y-dian[i].y)
);
}
return ret;
}
int main()
{
int i,ncase=1;
while(scanf("%d",&n),n)
{
for(i=0;i<n;++i)
{
scanf("%lf%lf%d%d",&dian[i].x,&dian[i].y,&info[i].v,&info[i].l);
}
int maxofi=(1<<n)-1;
int cutvalue=999999999;
double l_sheng;
int cutn;
vector<int> cut;
vector<int> tempcut;
point work[20];
for(i=0;i<maxofi;++i)
{
int tempcutn,shengyun;
int tempcutv,cutl;
int ret;
double zhouchang;
getpoint(i,dian,work,tempcut,tempcutn,shengyun,tempcutv,cutl);
if(shengyun==1)
{
zhouchang=0;
}else if(shengyun==2)
{
zhouchang=mo_distance(work[0],work[1])*2;
}else
{
ret=mo_graham(shengyun,work,zhan);
zhouchang=zhou(zhan,ret);
} if(mo_ge(cutl,zhouchang))
{
if(tempcutv<cutvalue)
{
cutvalue=tempcutv;
l_sheng=cutl-zhouchang;
cut=tempcut;
cutn=tempcutn;
}else if(tempcutv==cutvalue&&tempcutn<cutn)
{
cutvalue=tempcutv;
l_sheng=cutl-zhouchang;
cut=tempcut;
cutn=tempcutn;
}
}
}
if(ncase!=1) printf("\n");
printf("Forest %d\n",ncase++);
printf("Cut these trees:");
int len=cut.size();
for(i=0;i<len;++i)
{
printf(" %d",cut[i]+1);
}
printf("\n");
printf("Extra wood: %.2lf\n",l_sheng);
}
return 0;
}

poj1873 The Fortified Forest 凸包+枚举 水题的更多相关文章

  1. Uva5211/POJ1873 The Fortified Forest 凸包

    LINK 题意:给出点集,每个点有个价值v和长度l,问把其中几个点取掉,用这几个点的长度能把剩下的点围住,要求剩下的点价值和最大,拿掉的点最少且剩余长度最长. 思路:1999WF中的水题.考虑到其点的 ...

  2. POJ 1873 The Fortified Forest [凸包 枚举]

    The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6400   Accepted: 1 ...

  3. POJ 1873 The Fortified Forest(枚举+凸包)

    Description Once upon a time, in a faraway land, there lived a king. This king owned a small collect ...

  4. POJ 1873 UVA 811 The Fortified Forest (凸包 + 状态压缩枚举)

    题目链接:UVA 811 Description Once upon a time, in a faraway land, there lived a king. This king owned a ...

  5. POJ 1873 The Fortified Forest 凸包 二进制枚举

    n最大15,二进制枚举不会超时.枚举不被砍掉的树,然后求凸包 #include<stdio.h> #include<math.h> #include<algorithm& ...

  6. POJ 1873 - The Fortified Forest 凸包 + 搜索 模板

    通过这道题发现了原来写凸包的一些不注意之处和一些错误..有些错误很要命.. 这题 N = 15 1 << 15 = 32768 直接枚举完全可行 卡在异常情况判断上很久,只有 顶点数 &g ...

  7. HDU 1017 A Mathematical Curiosity (枚举水题)

    Problem Description Given two integers n and m, count the number of pairs of integers (a,b) such tha ...

  8. CodeForces 444C. DZY Loves Physics(枚举+水题)

    转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207 题目链接:http://codeforces.com/contest/ ...

  9. 方程的解——枚举&&水题

    题目 链接 给出方程组:$$\displaystyle \left\{\begin{aligned}11x + 13y + 17z = 2471 \\13x + 17y + 11z = 2739\en ...

随机推荐

  1. Core管道中的处理流程3

    通过重建Hosting系统理解HTTP请求在ASP.NET Core管道中的处理流程[下]:管道是如何构建起来的? 在<中篇>中,我们对管道的构成以及它对请求的处理流程进行了详细介绍,接下 ...

  2. Ubuntu14.04下Unity桌面托盘图标显示问题

    本来想丰富一下功能,遂开始安装大开眼界:Ubuntu下10个厉害的Indicator小程序这里的Indicator小程序. 很不幸,在安装到indicator-multiload的时候,准备注销看一下 ...

  3. public void Delete(List EntityList) where T : class, new()类型参数约束

    查找后发现这是类型参数约束,.NET支持的类型参数约束有以下五种: where T : struct | T必须是一个结构类型 where T : class T必须是一个类(class)类型 whe ...

  4. HDU 2045 不容易系列之(3)—— LELE的RPG难题(递推)

    点我看题目 题意 : 中文题不解释. 思路  :先算了第3个第4个,算的时候发现只要在已经枚举出来的前边的状态中往后添加字母就行了,如果两个的都已经表示出来了,那第三个就可以在每个第二个后边加一个,在 ...

  5. 上次的AJAX定时刷新多ID不正确,这次请教了高手之后补全

    关键是setInterval无法传递参数,所以用了匿名函数再包裹一下就好了. //重置发布进度 function resetPercent(id_data){ $.ajax({ url:'/autod ...

  6. Linux内核态抢占机制分析

    http://blog.sina.com.cn/s/blog_502c8cc401012pxj.html [摘要]本文首先介绍非抢占式内核(Non-Preemptive Kernel)和可抢占式内核( ...

  7. 页面上动态编译及执行java代码

    本文地址:http://www.cnblogs.com/liaoyu/p/real-time-compile-and-run-java-code-web-app.html 最近看到同事在页面上编译和执 ...

  8. hbase安装(zookeeper等)

    文库:http://wenku.baidu.com/link?url=5mnYL7ZuxUBWZnrnmak4JRVF5fJquJmjgmZy788i7UW8lUk4QXD8Nc_haPz33vjt9 ...

  9. JAVA bean与XML互转的利器---XStream

    最近在项目中遇到了JAVA bean 和XML互转的需求, 本来准备循规蹈矩使用dom4j忽然想起来之前曾接触过的XStream, 一番研究豁然开朗,利器啊利器, 下来就XStream的一些用法与大家 ...

  10. MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类

    MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型.是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器 ...