注意:

一共n位,所以i从1枚举到 (1<

#include <iostream>
#include <cmath>
#include <cstdio>
#include <string.h>
#include <algorithm>
#define pi acos(-1)
#define eps 1e-8
using namespace std;struct point{double x,y,v,len;int num;point(){}point(double xx,double yy){x=xx,y=yy;}double operator * (point t){return x*t.y - t.x*y;}point operator - (point t){return point(x-t.x,y-t.y);}
}a[20],b[20];
bool cmp(point a,point b){return a.x < b.x;
}
double dis(point a,point b){return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
}
point stak[1000];
int vis[200],needv;double sumlen = 0,needlen = 0;double graham(int n){for(int i = 1;i <= n;i++){b[i] = a[i];}sort(b+1, b+1+n,cmp);int r,top=0,m;for(int i = 1; i <= n; i++) {if(vis[ b[i].num ] == 1) continue;while(top>1 && (stak[top]-stak[top-1])*(b[i]-stak[top]) <= 0 ) top--;stak[++top] = b[i];}m = top;for(int i = n-1; i >= 1; i--) {if(vis[b[i].num] == 1) continue;while(top>m && (stak[top]-stak[top-1])*(b[i]-stak[top]) <= 0 ) top--;stak[++top] = b[i];}for(int i = 2;i<=top;i++){needlen += dis(stak[i],stak[i-1]);}return needlen;
}
int  f(int i){memset(vis,0,sizeof(vis));sumlen = 0,needlen = 0,needv=0;int cnt = 0;for(int j = 1;i != 0;i>>=1,j++){if(i&1){vis[j] = 1;sumlen += a[j].len;cnt++;needv += a[j].v;}}return cnt;
}int main(){int n,l,ncase=0;while(~scanf("%d",&n),n){ncase++;for(int i = 1;i <= n;i++){scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&a[i].v,&a[i].len);a[i].num = i;}int delimiter = (1<<(n));int ans = 100;int ansi = 0,ansv = 0x3f3f3f3f;for(int i = 1;i < delimiter;i++){int cnt_del = f(i);if(needv > ansv) continue;graham(n);if(needlen <= sumlen+eps && ansv > needv){ans = cnt_del,ansi = i;ansv = needv;}else if(needlen <= sumlen+eps && ansv == needv && ans > cnt_del){ansi = i;ans = cnt_del;}}f(ansi);graham(n);printf("Forest %d\n",ncase);printf("Cut these trees: ");for(int i = 1;i <= n;i++){if(vis[i] == 1)printf("%d ",i);}puts("");printf("Extra wood: %.2f\n\n",sumlen-needlen);}return 0;
}

poj 1873The Fortified Forest (凸包 二进制枚举)相关推荐

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

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

  2. POJ-1873-The Fortified Forest(二进制枚举+凸包)

    题目链接:http://poj.org/problem?id=1873 题目大意:给出n棵树的位置(x,y)坐标,价值v和长度l.让你从中选择一些树,砍掉他们将其他的树围起来. 要求砍的这些树的价值之 ...

  3. poj 1873 The Fortified Forest (位运算枚举 + 凸包周长)

    题目链接:http://poj.org/problem?id=1873 大意:有一片N棵树的森林,要从中砍掉几棵树做成篱笆,把剩下的树围起来 输入:给N课树,每棵树的坐标是x,y,每棵树有一个vi和l ...

  4. Uva5211/POJ1873 The Fortified Forest 凸包

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

  5. The Fortified Forest UVALive - 5211 [二进制枚举+凸包周长]

    The Fortified Forest UVALive - 5211 题意:n棵树,每棵树对应有x,y,v,l分别代表横坐标,纵坐标,价值,砍这棵树能构成的篱笆长度.现在要求输出,在最小被砍价值的情 ...

  6. POJ 1873 The Fortified Forest(枚举+凸包+剪枝)

    POJ 1873 The Fortified Forest 题意: 某王有一些树,要制作一个栅栏将所有树围起来,栅栏制作木材来源就是砍去其中一些树. 现在输入每棵树的坐标,价值,高度,求出所围价值最大 ...

  7. 【poj】1873: The Fortified Forest (凸包+状态压缩+各种搞事)

    题目描述: The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7818   Accep ...

  8. The Fortified Forest POJ - 1873

    The Fortified Forest POJ - 1873 题意:n棵树,砍掉一些树做木材将剩余的树围起来. n较小,二进制枚举~ 1 #include <cstdio> 2 #inc ...

  9. uva 811 - The Fortified Forest(暴力+凸包)

    题目链接:uva 811 - The Fortified Forest 最多就15棵树,枚举哪些树要砍,剩下的做凸包. #include <cstdio> #include <cst ...

最新文章

  1. web project、web service project和java project的区别
  2. Java API概述及应用
  3. elasticsearch集群部署
  4. HDU5961 —— 传递【竞赛图】【判断传递闭包】
  5. 编译工具链和交叉编译工具链简易说明
  6. C++中fftw库二维傅里叶变换笔记
  7. java生成图片中文乱码_Java生成图片乱码问题的解决方法
  8. Mac使用U盘重装系统
  9. PLC可编程控制器、单片机开发应用及电气控制综合实训装置
  10. BZOJ 3097: Hash Killer I
  11. 2020年鼠年正月十二 淡然面对
  12. 使用uniapp编写词霸每日一句页面
  13. Mac下查看本机IP地址
  14. hadoop暂时永久关闭安全模式
  15. 使用H5中的video标签时,页面中间显示“暂停”图标;点击播放,图标消失;点击暂停,图标出现(play、pause、ended)
  16. 制作MMORPG游戏需要储备哪些门子技术
  17. AutoJs学习-实现某音点赞自动回复
  18. pytorch使用gpu(linux服务器上)
  19. 人教版五年级计算机教案,人教版五年级上册信息技术教案
  20. Vrep的matlab接口

热门文章

  1. 逆水寒江湖无限服务器等级,逆水寒·如何看待:开设服务器技能等级上限
  2. Jquery+ASP.NET 实现开心网上传头像剪裁功能[转]
  3. 阿里云免费服务器申请与基本必要配置
  4. MySQL数据库访问性能优化
  5. RIP1 激酶抑制剂可应用于自身免疫性脑脊髓炎的治疗
  6. 旗帜第一、二次考核反思与总结
  7. CART分类决策树:kaggle泰坦尼克号存活率预测(不调库,手工推)
  8. html字符串img添加style,js 匹配 img标签 增加 style样式
  9. 【重点】关于HPIPS开始解锁冻结通证的公告
  10. python教程80--两个Excel表做对比,找出表的值有哪些差异