链接

居然是WF的水题~

二进制枚举砍哪些树,剩余的树围成一个凸包。

因为传数组WA了两发,忘记修改排序数组中的p[0];

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 20
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
int x,y;
int vi,li;
point(int x=,int y=):x(x),y(y){}
}p[N],q[N],ch[N];
int o[N],f[N];
typedef point pointt;
pointt operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double cross(point a,point b)
{
return 1.0*a.x*b.y-a.y*b.x;
}
double mul(point p0,point p1,point p2)
{
return cross(p1-p0,p2-p0);
}
double dis(point a)
{
return sqrt(1.0*a.x*a.x+a.y*a.y);
}
bool cmp(point a,point b)
{
if(dcmp(mul(q[],a,b))==)
return dis(a-q[])<dis(b-q[]);
else
return dcmp(mul(q[],a,b))>;
}
double Graham(int n)
{
if(n<=) return ;
if(n==) return *dis(q[]-q[]);
int i,k = ,top;
point tmp;
for(i = ; i < n; i++)
{
if(q[i].y<q[k].y||(q[i].y==q[k].y&&q[i].x<q[k].x))
k = i;
}
if(k!=)
{
tmp = q[];
q[] = q[k];
q[k] = tmp;
}
sort(q+,q+n,cmp);
ch[] = q[];
ch[] = q[];
top = ;
for(i = ; i < n ; i++)
{
while(top>&&dcmp(mul(ch[top-],ch[top],q[i]))<)
top--;
top++;
ch[top] =q[i];
}
ch[top+] = ch[];
double len = ;
for(i = ; i <= top ; i++)
len+=dis(ch[i]-ch[i+]);
return len;
}
int main()
{
int n,i,j,g;
int kk = ;
while(scanf("%d",&n)&&n)
{
for(i = ; i <n ;i++)
scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i].vi,&p[i].li);
int num;
int ans = INF;
double res = ;
for(i = ; i < (<<n) ; i++)
{
g = ;
int gg = ;
int tv = ;
double tlen = ;
for(j = ;j < n; j++)
{
if((<<j)&i)
{
f[gg++] = j;
tlen+=p[j].li;
tv += p[j].vi;
}
else q[g++] = p[j];
}
double len = Graham(g);
if(dcmp(tlen-len)>=)
{
if(ans>tv||(ans==tv&&num>gg))
{
ans = tv;
num = gg;
res = tlen-len;
//cout<<len<<" "<<i<<endl; for(j = ; j < gg ; j++)
o[j] = f[j]+;
}
}
}
if(kk) puts("");
printf("Forest %d\n",++kk);
printf("Cut these trees: ");
for(i = ; i < num-; i++)
printf("%d ",o[i]);
if(num)
printf("%d\n",o[num-]);
printf("Extra wood: %.2f\n",res);
}
return ;
}

poj1873The Fortified Forest的更多相关文章

  1. poj1873 The Fortified Forest 凸包+枚举 水题

    /* poj1873 The Fortified Forest 凸包+枚举 水题 用小树林的木头给小树林围一个围墙 每棵树都有价值 求消耗价值最低的做法,输出被砍伐的树的编号和剩余的木料 若砍伐价值相 ...

  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 凸包 + 搜索 模板

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

  4. 简单几何(凸包+枚举) POJ 1873 The Fortified Forest

    题目传送门 题意:砍掉一些树,用它们做成篱笆把剩余的树围起来,问最小价值 分析:数据量不大,考虑状态压缩暴力枚举,求凸包以及计算凸包长度.虽说是水题,毕竟是final,自己状压的最大情况写错了,而且忘 ...

  5. The Fortified Forest - POJ 1873(状态枚举+求凸包周长)

    题目大意:有个国王他有一片森林,现在他想从这个森林里面砍伐一些树木做成篱笆把剩下的树木围起来,已知每个树都有不同的价值还有高度,求出来砍掉那些树可以做成篱笆把剩余的树都围起来,要使砍伐的树木的价值最小 ...

  6. POJ 1873 The Fortified Forest

    题意:是有n棵树,每棵的坐标,价值和长度已知,要砍掉若干根,用他们围住其他树,问损失价值最小的情况下又要长度足够围住其他树,砍掉哪些树.. 思路:先求要砍掉的哪些树,在求剩下的树求凸包,在判是否可行. ...

  7. ●POJ 1873 The Fortified Forest

    题链: http://poj.org/problem?id=1873 题解: 计算几何,凸包 枚举被砍的树的集合.求出剩下点的凸包.然后判断即可. 代码: #include<cmath> ...

  8. POJ 1873 The Fortified Forest(凸包)题解

    题意:二维平面有一堆点,每个点有价值v和删掉这个点能得到的长度l,问你删掉最少的价值能把剩余点围起来,价值一样求删掉的点最少 思路:n<=15,那么直接遍历2^15,判断每种情况.这里要优化一下 ...

  9. Uva5211/POJ1873 The Fortified Forest 凸包

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

随机推荐

  1. mysql同步

    已安装好mysql,并且已把配置文件复制在/etc/my.cnf 主服务器的配置: 1,查看二进制日志的状态,开启二进制日志 进入mysql安装目录 #cd /usr/local/mysql 进入my ...

  2. 使用percona xtradb cluster的IST方式添加新节点

    使用percona xtradb cluster的IST(Incremental State Transfer)特性添加新节点,防止新节点加入时使用SST(State SnapShop Transfe ...

  3. StringUtils中 isEmpty 和isBlank的区别

    StringUtils方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出Nu ...

  4. DevExpress.XtraGrid.Views.BandedGrid.BandedGridView

    使用的是DevExpress.XtraGrid.Views.BandedGrid.BandedGridView 类 没有在工具箱里找到对应控件 ,绕了一下,先创建一个gridcontrol ,然后gr ...

  5. A Round Peg in a Ground Hole(凸包应用POJ 1584)

    A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5684 Accepte ...

  6. zoj Abs Problem

    Abs Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Alice and Bob is pl ...

  7. XMLHttpRequest 2.0与FileReader接口的方法

    jsonpd的实现: var jsonp = function (options) { var url = options.url, params = options.params || {}, ca ...

  8. Java中自定义异常

    /*下面做了归纳总结,欢迎批评指正*/ /*自定义异常*/ class ChushulingException extends Exception { public ChushulingExcepti ...

  9. VS2015使用技巧 打开代码片段C#部分

    镇场诗: 大梦谁觉,水月中建博客.百千磨难,才知世事无常. 今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ 1. ...

  10. 修改 OWA 修改密码的生效时间

    从 Exchange 中文站之前的文章配置 OWA 下次登录时更改密码中, 我们知道在 Exchange 2010 SP1 当中是可以配置在 OWA 中修改域用户的密码的,那么不知道你是否有发现,当用 ...