// 凸包模板 POJ1873
// n=15所以可以按位枚举求凸包,再记录数据 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const double inf = 0x3f3f3f3f;
const LL MOD =100000000LL;
const int N =;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} int sgn(double x){
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
} struct Point{
double x,y;
Point(){}
Point(double _x,double _y){
x = _x;y = _y;
}
Point operator -(const Point &b)const{
return Point(x - b.x,y - b.y);
}
double operator ^(const Point &b)const{
return x*b.y - y*b.x;
}
double operator *(const Point &b)const{
return x*b.x + y*b.y;
}
friend bool operator<(const Point &a,const Point &b){
if(fabs(a.y-b.y)<eps) return a.x<b.x;
return a.y<b.y;
}
friend double dis2(Point a){
return a.x*a.x+a.y*a.y;
}
}; double dis(Point a,Point b){
return sqrt(dis2(a-b));
}
double mult(Point a,Point b,Point o){
return (a.x-o.x)*(b.y-o.y)>=(b.x-o.x)*(a.y-o.y);
} Point P[];
double v[],l[]; double graham(Point p[],int n,Point q[]){
int top=;
sort(p,p+n);
if(n==) return ;
q[]=p[];
if(n==) return ;
q[]=p[];
if(n==) return dis(p[],p[])*;
q[]=p[];
for(int i=;i<n;i++){
while(top&&(mult(p[i],q[top],q[top-]))) top--;
q[++top]=p[i];
}
int len=top;
q[++top]=p[n-];
for(int i=n-;i>=;i--){
while(top!=len&&(mult(p[i],q[top],q[top-]))) top--;
q[++top]=p[i];
}
double c=dis(q[],q[top-]);
for(int i=;i<top-;i++)
c+=dis(q[i],q[i+]);
return c;
} int n;
int b[],a[];
Point p[],ch[];
int main(){
int cas=;
while(~scanf("%d",&n),n){
for(int i=;i<n;i++){
double x,y;
scanf("%lf%lf%lf%lf",&x,&y,&v[i],&l[i]);
P[i]=Point(x,y);
}
int k,cnt;
double ans=;
int minn_cnt=;
double sum,len,minn=inf;
for(int st=;st<(<<n);st++){
sum=,len=,k=,cnt=; for(int i=;i<n;i++){
if(st&(<<i)){
sum+=v[i];
len+=l[i];
b[++cnt]=i+;
}
else{
p[k++]=P[i];
}
}
double lenn=graham(p,k,ch);
if(lenn>len) continue;
if(sum<minn||(sum==minn&&cnt<minn_cnt)){
minn=sum;
minn_cnt=cnt;
ans=len-lenn;
for(int i=;i<=cnt;i++){
a[i]=b[i];
}
}
}
printf("Forest %d\n",cas++);
printf("Cut these trees:");
for(int i=;i<=minn_cnt;i++){
printf(" %d",a[i]);
}
printf("\n");
printf("Extra wood: ");
printf("%.2f\n",ans);
printf("\n");
}
return ;
}

凸包模板 POJ1873的更多相关文章

  1. 计算几何(凸包模板):HDU 1392 Surround the Trees

    There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So a ...

  2. hdu 2202 最大三角形_凸包模板

    题意:略 思路:直接套用凸包模板 #include <iostream> #include <cstdio> #include <cmath> #include & ...

  3. hdu 1348 凸包模板

    http://acm.hdu.edu.cn/showproblem.php?pid=1348 造城墙问题,求出凸包加上一圈圆的周长即可 凸包模板题 #include <cstdio> #i ...

  4. Poj 2187 凸包模板求解

    Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...

  5. 凸包模板——Graham扫描法

    凸包模板--Graham扫描法 First 标签: 数学方法--计算几何 题目:洛谷P2742[模板]二维凸包/[USACO5.1]圈奶牛Fencing the Cows yyb的讲解:https:/ ...

  6. HDU 1392 Surround the Trees(几何 凸包模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1392 题目大意: 二维平面给定n个点,用一条最短的绳子将所有的点都围在里面,求绳子的长度. 解题思路: 凸包的模 ...

  7. hdu4266(三维凸包模板题)

    /*给出三维空间中的n个顶点,求解由这n个顶点构成的凸包表面的多边形个数. 增量法求解:首先任选4个点形成的一个四面体,然后每次新加一个点,分两种情况: 1> 在凸包内,则可以跳过 2> ...

  8. POJ 3348 Cows | 凸包模板题

    题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...

  9. POJ3528 HDU3662 三维凸包模板

    POJ3528 HDU3662 第一道题 给定若干点 求凸包的表面积,第二题 给定若干点就凸包的面数. 简单说一下三维凸包的求法,首先对于4个点假设不共面,确定了唯一四面体,对于一个新的点,若它不在四 ...

随机推荐

  1. xpath选择器使用

    简单说,xpath就是选择XML文件中节点的方法. 所谓节点(node),就是XML文件的最小构成单位,一共分成7种. - element(元素节点)- attribute(属性节点)- text ( ...

  2. Maven —— 如何设置HTTP代理

    公司需要设置代理才能上网,而运行Maven时需要下载依赖的库. 怎么办呢? 原来Maven也像IE一样,可以设置代理的. 步骤如下: ·编辑 ~/.m2/setting.xml 文件.如果该目录下没有 ...

  3. 二维码(2)二维码登录原理及Android客户端示例

    1,原理 服务器: 数据库: 建立一个2维码登录的数据表,产生一个登录页时,插入一条记录X,X含将要登录的用户名字段(初始为空),2维码中的数据字段(唯一) 登录页面: 在产生的2维码中包含关键数据Y ...

  4. .net类库中和数据库相关的

    System.Data.SqlTypes SqlDbType 枚举类型 Specifies SQL Server-specific data type of a field, property, fo ...

  5. 第十篇 PO核心功能及流程详解

    详见链接:http://bbs.erp100.com/thread-272866-1-1.html1. P2P lifecycleP2P是procure to pay的缩写,p2p循环值得就是采购到付 ...

  6. leetcode:Power of Two

    Given an integer, write a function to determine if it is a power of two. 分析:这道题让我们判断一个数是否为2的次方数(而且要求 ...

  7. 【笨嘴拙舌WINDOWS】实践检验之按键精灵【Delphi】

    通过记录键盘和鼠标位置和输入信息,然后模拟发送,就能够创建一个按键精灵! 主要代码如下: library KeyBoardHook; { Important note about DLL memory ...

  8. HTML5学习总结——HTML5新增属性与表单元素

    一HTML5新增属性 1.1contcxtmcnu contextmenu的作用是指定右键菜单. <!DOCTYPE html> <html> <head> < ...

  9. MYSQL数据库管理之权限管理

    经常遇到有网友在QQ群或者论坛上问关于mysql权限的问题,今天抽空总结一下关于这几年使用MYSQL的时候关于MYSQL数据库的权限管理的经验,也希望能对使用mysql的网友有所帮助! 一.MYSQL ...

  10. IE 火狐浏览器对时间格式的兼容性;使用原型对象的方式 prototype关键字;时间格式化

    在ie中 时间格式如果用横杠来显示  "2013-05-10 19:20:59" 是可以正确识别的(如果用斜杠,IE也可以正确识别), 但是如果是火狐,则只能识别斜杠模式 &quo ...