题链:

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. mobiscroll2.5.4 日期组件

    <script type="text/javascript"> function setCss(o) { $('input:jqmData(role="dat ...

  2. 小黄衫 Get

    小黄衫 Get .   十分荣幸在前四次作业中以微弱的3分之差拿到了第一,获得了本次的小黄衫. 先发点牢骚.. 讲道理,原本以为的研究生生涯应该就是埋在论文堆里度过的时候顺便上上课.当初选课的时候,学 ...

  3. webView调用系统地图,电话,和跳转链接的方法

    webView.dataDetectorTypes = UIDataDetectorTypePhoneNumber | UIDataDetectorTypeLink | UIDataDetectorT ...

  4. Junit 4 测试中使用定时任务操作

    难度:测试中执行线程操作 package com.hfepc.job.dataCollection.test; import java.util.Date; import java.util.List ...

  5. 【原创】Webpack构建中hash的优化

    背景: SPA的vue应用,采用webpack2构建,打包入口为main.js 输出:main模块打包成app.js,公共lib打包成vendor.js,公共样式打包成app.css,运行时依赖打包成 ...

  6. windows7.0旗舰版安装后控制面板自带的Microsoft程序

    1.不要卸载,否则会出现安装其他软件时缺少动态链接库

  7. HTTP协议扫盲(二)HTTP协议的请求方法、请求头和响应头

    一.HTTP请求方法 Http协议定义了很多与服务器交互的方法,最基本的有4种,分别是GET,POST,PUT,DELETE. 一个URL地址用于描述一个网络上的资源,而HTTP中的GET, POST ...

  8. SQL字符串操作汇总

    SQL字符串操作汇总 --将字符串中从某个字符开始截取一段字符,然后将另外一个字符串插入此处 select stuff('hello,world!',4,4,'****')   --返回值hel*** ...

  9. c语言清屏、等待、随机函数

    清屏函数 #include<conio.h> system("CLS");或system(cls); 等待函数 #include<windows.h>  S ...

  10. POJ-3268 Silver Cow Party---正向+反向Dijkstra

    题目链接: https://vjudge.net/problem/POJ-3268 题目大意: 有编号为1-N的牛,它们之间存在一些单向的路径.给定一头牛的编号X,其他牛要去拜访它并且拜访完之后要返回 ...