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中的水题.考虑到其点的 ...
随机推荐
- ORACLE--分区表数据清理
由于分区表数据增加:没做清除操作:导致表空间告急.需要清理很久之前的数据:释放空间.步骤如下 一,查看哪个表占的空间 SELECT t.segment_name, SUM(t.bytes / 1024 ...
- ACM题目————STL练习之字符串替换
描述 编写一个程序实现将字符串中的所有"you"替换成"we" 输入 输入包含多行数据 每行数据是一个字符串,长度不超过1000 数据以EOF结束 输出 对于输 ...
- 怎样解决:未找到路径“……”的控制器或该控制器未实现 IController?
就是要加上new{area=""},比如下面的: @{Html.RenderAction("Cartsummary","ShoppingCart&qu ...
- Prompt isNaN 数组 function DOM window.open/close/location/history
1.prompt的利用 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Defa ...
- yum报错
用man clean all man yum,可以看到,clean选项的作用是: Is used to clean up various things which accumulate in th ...
- 2-Babel
一.什么是babel babel是一个源代码到源代码的转换器.比较广泛的用法就是可以把你写的符合 ECMAScript 6 标准的代码完美地转换为 ECMAScript 5 标准的代码,并且可以确保良 ...
- 【leetcode❤python】141. Linked List Cycle
#-*- coding: UTF-8 -*- #Method:快慢指针法,建立虚表头,快指针走两步,慢指针走一步,若存在环,则快指针会追上慢指针# Definition for singly-link ...
- CSS3弹力球
如下代码实现方块在限定区域内不停弹跳. <!DOCTYPE html> <html> <head> <style> div { width:100px; ...
- jquery之html(),text()方法详解
一:html() html()函数用于设置或返回当前jQuery对象所匹配的DOM元素内的html内容. 该函数的用途相当于设置或获取DOM元素的innerHTML属性值. 该函数属于jQuery对象 ...
- Atlassian如何实施DevOps
DevOps是推动开发和运维团队之间沟通和协作的手段.它不是一个工具或产品.相反,其成功的首要因素就是文化.目的是更快的创新和更好的客户体验. "2015年DevOps状态报告"调 ...