题链:

http://poj.org/problem?id=1873

题解:

计算几何,凸包

枚举被砍的树的集合。求出剩下点的凸包。然后判断即可。

代码:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=16,INF=0x3f3f3f3f;
const double eps=1e-8;
int sign(double x){
if(fabs(x)<=eps) return 0;
return x<0?-1:1;
}
struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){}
void Read(){scanf("%lf%lf",&x,&y);}
}D[MAXN],H[MAXN];
typedef Point Vector;
bool operator < (Point A,Point B){return sign(A.x-B.x)<0||(sign(A.x-B.x)==0&&sign(A.y-B.y)<0);}
bool operator == (Point A,Point B){return sign(A.x-B.x)==0&&sign(A.y-B.y)==0;}
Vector operator - (Point A,Point B){return Vector(A.x-B.x,A.y-B.y);}
double operator ^ (Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double operator * (Vector A,Vector B){return A.x*B.x+A.y*B.y;}
int V[MAXN],N,ansS,ansV,ansN;
double L[MAXN],resL;
double GL(Vector A){//Get_Length
return sqrt(A*A);
}
int Andrew(int S){
int hnt=0,k=0,tnt=0;
static Point tmp[MAXN];
for(int i=1;i<=N;i++) if(!(S&(1<<(i-1)))) tmp[++tnt]=D[i];
sort(tmp+1,tmp+tnt+1);
tnt=unique(tmp+1,tmp+tnt+1)-tmp-1;
for(int i=1;i<=tnt;i++){
while(hnt>1&&sign((H[hnt]-H[hnt-1])^(tmp[i]-H[hnt-1]))<=0) hnt--;
H[++hnt]=tmp[i];
} k=hnt;
for(int i=tnt-1;i>=1;i--){
while(hnt>k&&sign((H[hnt]-H[hnt-1])^(tmp[i]-H[hnt-1]))<=0) hnt--;
H[++hnt]=tmp[i];
}
return hnt;
}
double GCPC(int hnt){//Get_Convex_Polygon_Circumference
double C=0;
for(int i=1;i<hnt;i++) C+=GL(H[i+1]-H[i]);
return C;
}
int main(){
double C,nowL;
int nowS,nowV,nowN,Case=0;
while(scanf("%d",&N)&&N){
if(N==0) break;
ansS=(1<<N)-1; ansV=INF; ansN=N; resL=0;
for(int i=1;i<=N;i++)
D[i].Read(),scanf("%d%lf",&V[i],&L[i]);
for(int S=1;S<=(1<<N)-1;S++){
nowS=S; nowN=0; nowL=0; nowV=0;
for(int i=1;i<=N;i++) if(S&(1<<(i-1)))
nowN++,nowV+=V[i],nowL+=L[i];
C=GCPC(Andrew(S));
if(sign(nowL-C)<0) continue;
if(nowV<ansV||(nowV==ansV&&nowN<ansN))
ansS=nowS,ansV=nowV,ansN=nowN,resL=nowL-C;
}
if (Case) puts("");
printf("Forest %d\n",++Case);
printf("Cut these trees:");
for(int i=1;i<=N;i++) if(ansS&(1<<(i-1))) printf(" %d",i);
printf("\nExtra wood: %.2lf\n",resL);
}
return 0;
}

  

●POJ 1873 The Fortified Forest的更多相关文章

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

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

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

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

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

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

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

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

  5. POJ 1873 The Fortified Forest

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

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

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

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

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

  8. poj 1873 凸包+枚举

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

  9. Uva5211/POJ1873 The Fortified Forest 凸包

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

随机推荐

  1. 201621123057 《Java程序设计》第1周学习总结

    1.本周学习总结 .java - - 源程序 .class - - 字节码文件 JVM - - 虚拟机 JRE - - 执行环境 JDK - - 开发工具包 其中,运行的是.class,而非.java ...

  2. 项目Beta冲刺Day7

    项目进展 李明皇 今天解决的进度 部分数据传递和使用逻辑测试 林翔 今天解决的进度 服务器端查看个人发布的action,修改已发布消息状态的action,仍在尝试使用第三方云存储功能保存图片 孙敏铭 ...

  3. scrapy 博客爬取

    item.py import scrapy class FulongpjtItem(scrapy.Item): # define the fields for your item here like: ...

  4. scrapy 数据存储mysql

    #spider.pyfrom scrapy.linkextractors import LinkExtractor from scrapy.spiders import CrawlSpider, Ru ...

  5. JAVA面向对象的多态性

    什么是多态?简而言之就是相同的行为,不同的实现. 而多态也分为静态多态(重载).动态多态(重写)和动态绑定. 静态动态,实际就是指的重载的概念,是系统在编译时,就能知晓该具体调用哪个方法.动态多态指在 ...

  6. eclipse下maven一些配置方法汇总

    随着eclipse的不同版本的变更:对maven插件的安装也有着不同的差异:之前也在一些版本的eclipse上安装成功地,但是最近又遇到了一些麻烦,故将这些方法记录下来: 大家都知道的最常用的一种方式 ...

  7. R语言基础1

    ----------------------------------R语言学习与科研应用,科研作图,数据统计挖掘分析,群:719954246-------------------------- 我们将 ...

  8. WPS怎么让前几页的页眉或者页脚与后面的不同

    其实不管利用WPS还是office对文档还是PPT进行操作,其实核心思想还是一种编程,主要是前端的编程,就是通过改变一些这些软件设置的样式,然后通过改变这些样式,使这些文字以老师要求的格式显示出来的, ...

  9. Hadoop完全分布式安装教程

    一.软件版本 Hadoop版本号:hadoop-2.6.0.tar: VMWare版本号:VMware-workstation-full-11.0.0-2305329 Ubuntu版本号:ubuntu ...

  10. Code::Blocks出现64-Bit mode not compled in解决方法

    原因是:Settings->compilter你选了Target x86 _64(64bit),选择Target x86 _32(32bit)即可 废了老半天劲才找到原因,希望能让朋友们少走弯路