题目链接:https://vjudge.net/problem/POJ-1873

题意:n个点(2<=n<=15),给出n个点的坐标(x,y)、价值v、做篱笆时的长度l,求选择哪些点来做篱笆围住另一些点,使得选出的这些点的价值和最小,如果价值和相等要求个数最小。

思路:

  看来这是WF的签到题吧。数据很小,直接二进制枚举 (1<<n),然后对未选出的点求凸包的周长,仅当选出点的长度l的和>=凸包周长时才更新答案。

AC code:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; const int maxn=;
const int inf=0x3f3f3f3f; struct Point{
int x,y;
Point():x(),y(){}
Point(int x,int y):x(x),y(y){}
}; int n,cas,val,num,res[maxn],v[maxn],l[maxn],vis[maxn];
double ext;
int top,stack[maxn];
Point pt[maxn],list[maxn]; int cross(Point p0,Point p1,Point p2){
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} double dis(Point p1,Point p2){
return sqrt((double)(p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
} bool cmp(Point p1,Point p2){
int tmp=cross(list[],p1,p2);
if(tmp>) return true;
else if(tmp==&&dis(list[],p1)<dis(list[],p2)) return true;
else return false;
} void init(int m){
Point p0=list[];
int k=;
for(int i=;i<m;++i){
if((p0.y>list[i].y)||((p0.y==list[i].y)&&(p0.x>list[i].x))){
p0=list[i];
k=i;
}
}
list[k]=list[];
list[]=p0;
sort(list+,list+m,cmp);
} double graham(int m){
if(m==){
top=;
stack[]=;
}
else{
top=;
stack[]=;
stack[]=;
for(int i=;i<m;++i){
while(top>&&cross(list[stack[top-]],list[stack[top]],list[i])<=) --top;
stack[++top]=i;
}
}
double ret=;
for(int i=;i<top;++i)
ret+=dis(list[stack[i]],list[stack[i+]]);
ret+=dis(list[stack[top]],list[stack[]]);
return ret;
} int main(){
while(scanf("%d",&n),n){
val=num=inf;
for(int i=;i<n;++i)
scanf("%d%d%d%d",&pt[i].x,&pt[i].y,&v[i],&l[i]);
for(int i=;i<(<<n)-;++i){
int t1=,t2=,cnt=;
for(int j=;j<n;++j){
if((i>>j)&){
t1+=v[j],t2+=l[j];
}
else{
list[cnt++]=pt[j];
}
}
init(cnt);
int cnt2=n-cnt;
if((t1<val)||((t1==val)&&(cnt2<num))){
double tmp=graham(cnt);
if(tmp>t2) continue;
val=t1,num=cnt2,ext=t2-tmp;
int t=;
for(int j=;j<n;++j){
if((i>>j)&)
res[t++]=j;
}
}
}
printf("Forest %d\nCut these trees:",++cas);
for(int i=;i<num;++i)
printf(" %d",res[i]+);
printf("\nExtra wood: %.2f\n\n",ext);
}
return ;
}

poj1873(二进制枚举+求凸包周长)的更多相关文章

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

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

  2. HDU 1392 凸包模板题,求凸包周长

    1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...

  3. poj 1113:Wall(计算几何,求凸包周长)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description ...

  4. Wall---hdu1348(求凸包周长 模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 求凸包周长+2*PI*L: #include <stdio.h> #include ...

  5. POJ 1113 Wall(Graham求凸包周长)

    题目链接 题意 : 求凸包周长+一个完整的圆周长. 因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 思路 : 求出凸包来,然后加上圆的周长 #include <stdi ...

  6. hdu 1392:Surround the Trees(计算几何,求凸包周长)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. hdu 1348:Wall(计算几何,求凸包周长)

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  8. HDU 1392 Surround the Trees (Graham求凸包周长)

    题目链接 题意 : 让你找出最小的凸包周长 . 思路 : 用Graham求出凸包,然后对每条边求长即可. Graham详解 #include <stdio.h> #include < ...

  9. poj1113Wall 求凸包周长 Graham扫描法

    #include<iostream> #include<algorithm> #include<cmath> using namespace std; typede ...

随机推荐

  1. FF,NF,BF

    设计一个可变式分区分配的存储管理方案.并模拟实现分区的分配和回收过程. 对分区的管理法可以是下面三种算法之一: 首次适应算法 循环首次适应算法 最佳适应算法 对于测试样例 : 首地址        大 ...

  2. LG5492 [PKUWC2018]随机算法

    题意 有一种贪心求最大独立集的算法: 随机一个排列 按顺序加入独立集,如果一个点能加入,就加入\({S}\) 给出一张图,问得出正确答案的概率. \(n \leq 20\) 传送门 思路 用 \(dp ...

  3. springboot读取外部配置文件

    springboot项目打成jar包后不好进行配置文件修改,可设置为读取外部配置文件,方便进行配置修改. 步骤: 1.将jar包中的application.properties配置文件复制到自定义路径 ...

  4. 【知识点】Java常用类库

    1.字符串 修改字符串内容用StringBuffer,没有“+”,需要用append(),否则用String 2.JVM 相关 Runtime,单例模式,通过getRuntime()获取实例,可以调用 ...

  5. MangoDB在C#中的使用

    http://blog.sina.com.cn/s/blog_927f3c2401011937.html 图形工具 http://api.mongodb.org/csharp/current/html ...

  6. lucene IndexOptions可以设置DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS DOCS,ES里也可以设置

    org.apache.lucene.index Enum Constants  Enum Constant and Description DOCS_AND_FREQS Only documents ...

  7. Mininet系列实验(六):Mininet动态改变转发规则实验

    一. 实验目的 熟悉Mininet自定义拓扑脚本的编写:熟悉编写POX脚本动态改变转发规则 二.实验原理 在SDN环境中,控制器可以通过对交换机下发流表操作来控制交换机的转发行为.在本实验中,基于Mi ...

  8. C++ vector 比较大小

    写在前: vector 是可以直接 进行比较. vector 默认提供的   operator< 内使用了  std::lexicographical_compare  进行比较, operat ...

  9. word中英文双引号的样式区分与替换技巧

    https://jingyan.baidu.com/article/3f16e003147ea42590c10349.html 场景:一篇word文档中,想要全选更改字体,使得中文全部为“宋体”,英文 ...

  10. angular之Rxjs异步数据流编程入门

    Rxjs介绍 参考手册:https://www.npmjs.com/package/rxjs 中文手册:https://cn.rx.js.org/ RxJS 是 ReactiveX 编程理念的 Jav ...