poj1873The Fortified Forest
居然是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的更多相关文章
- poj1873 The Fortified Forest 凸包+枚举 水题
/* poj1873 The Fortified Forest 凸包+枚举 水题 用小树林的木头给小树林围一个围墙 每棵树都有价值 求消耗价值最低的做法,输出被砍伐的树的编号和剩余的木料 若砍伐价值相 ...
- POJ 1873 The Fortified Forest [凸包 枚举]
The Fortified Forest Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6400 Accepted: 1 ...
- POJ 1873 - The Fortified Forest 凸包 + 搜索 模板
通过这道题发现了原来写凸包的一些不注意之处和一些错误..有些错误很要命.. 这题 N = 15 1 << 15 = 32768 直接枚举完全可行 卡在异常情况判断上很久,只有 顶点数 &g ...
- 简单几何(凸包+枚举) POJ 1873 The Fortified Forest
题目传送门 题意:砍掉一些树,用它们做成篱笆把剩余的树围起来,问最小价值 分析:数据量不大,考虑状态压缩暴力枚举,求凸包以及计算凸包长度.虽说是水题,毕竟是final,自己状压的最大情况写错了,而且忘 ...
- The Fortified Forest - POJ 1873(状态枚举+求凸包周长)
题目大意:有个国王他有一片森林,现在他想从这个森林里面砍伐一些树木做成篱笆把剩下的树木围起来,已知每个树都有不同的价值还有高度,求出来砍掉那些树可以做成篱笆把剩余的树都围起来,要使砍伐的树木的价值最小 ...
- POJ 1873 The Fortified Forest
题意:是有n棵树,每棵的坐标,价值和长度已知,要砍掉若干根,用他们围住其他树,问损失价值最小的情况下又要长度足够围住其他树,砍掉哪些树.. 思路:先求要砍掉的哪些树,在求剩下的树求凸包,在判是否可行. ...
- ●POJ 1873 The Fortified Forest
题链: http://poj.org/problem?id=1873 题解: 计算几何,凸包 枚举被砍的树的集合.求出剩下点的凸包.然后判断即可. 代码: #include<cmath> ...
- POJ 1873 The Fortified Forest(凸包)题解
题意:二维平面有一堆点,每个点有价值v和删掉这个点能得到的长度l,问你删掉最少的价值能把剩余点围起来,价值一样求删掉的点最少 思路:n<=15,那么直接遍历2^15,判断每种情况.这里要优化一下 ...
- Uva5211/POJ1873 The Fortified Forest 凸包
LINK 题意:给出点集,每个点有个价值v和长度l,问把其中几个点取掉,用这几个点的长度能把剩下的点围住,要求剩下的点价值和最大,拿掉的点最少且剩余长度最长. 思路:1999WF中的水题.考虑到其点的 ...
随机推荐
- JavaEE基础(二十七)/反射、JDK新特性
1.反射(类的加载概述和加载时机) A:类的加载概述 当程序要使用某个类时,如果该类还未被加载到内存中,则系统会通过加载,连接,初始化三步来实现对这个类进行初始化. 加载 就是指将class文件读入 ...
- POSTGRESQL9.5之pg_rman工具
pg_rman是一款专门为postgresql设计的在线备份恢复的工具.其支持在线和基于时间点备份方式,还可以通过创建backup catalog来维护DB cluster备份信息. 看起来好像是模仿 ...
- 浅谈SQL中的单引号
单引号:对很对计算机语言包括(SQL)是做字符串引用的:这个是大家通常知道的作用:但是对SQL语言来说:还有另外一个作用是作引号的转义 总结下:对oracle(sql)的作用. 做字符串引用:例如'a ...
- ab测试大并发错误
转载自http://xmarker.blog.163.com/blog/static/226484057201462263815783 apache 自带的ab工具测试,当并发量达到1000多的时候报 ...
- [c++][语言语法]函数模板和模板函数 及参数类型的运行时判断
参考:http://blog.csdn.net/beyondhaven/article/details/4204345 参考:http://blog.csdn.net/joeblackzqq/arti ...
- ACM题目————Robot Motion
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
- 为开发者准备的9个实用PHP代码片段
一.查看邮件是否已被阅读 当你发送邮件时,你肯定很想知道你的邮件是否已被对方查看.下面的代码就能实现记录阅读你邮件的IP地址,还有实际的阅读日期和时间. error_reporting(0);Head ...
- 对table的tr使用display:block显示colspan失效问题的解决
qqqq <table> <tr> <td id="qqq" colspan="3" style="display:no ...
- Mybatis like 模糊查询问题
1.mysql:LIKE CONCAT('%',#{empname},'%' ) 或者 LIKE CONCAT('%',‘${empname}’,'%' ) 2.oracle:LIKE '%'||#{ ...
- Linux下常用的shell命令记录1
硬件篇 CPU相关 lscpu #查看的是cpu的统计信息. cat /proc/cpuinfo #查看CPU信息详细信息,如每个CPU的型号,主频等 内存相关 free -m #概要查看内存情况 ...