// 凸包模板 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. Linux内网环境DNS修改域名指向,JAVA应用程序能否实时切换的问题总结

    公司内网环境中许多调用资源(数据库.web接口等)都是通过内网DNS服务来进行域名-IP的映射. 但经常出现DNS映射修改完毕后,应用中连接的资源迟迟没有变更. 以前一直笼统的认为是linux的dns ...

  2. php 传址

    在php 中引用的意思是:不同的名字访问同一个变量内容. 变量的引用 PHP 的引用允许你用两个变量来指向同一个内容 例一: <?php $a="2010"; $b =&am ...

  3. PHP,单项查询及多项查询

    先封装对象class DBDA { public $host = "localhost"; //数据库地址 public $uid = "root"; //数据 ...

  4. HDOJ ----Phone List

    Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. Maven POM.xml详解[转]

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  6. solr在电商平台中的使用示例简析

    来源:http://blog.csdn.net/yangbutao/article/details/9450463 在电商平台中搜索是非常重要的功能,主要包括有搜索词类目导航.自动提示和搜索排序功能 ...

  7. binary-tree-maximum-path-sum(mock)

    注意: // 注意,如果一个类放在另一个类里面,初始化时候会报错 Solution is not a enclosing class// 这是因为如果TreeNode不是static,那么要求先有外部 ...

  8. HTML中多媒体的应用_Flash/MP3/设置可以活动的文字

    一.HTML中多媒体的应用_falsh动画(往网页中插入Flash动画) 1. Flash动画插入第一种方法:使用<embed>...</embed>标记动画会自动缩小 属性: ...

  9. Machine Learning for hackers读书笔记(二)数据分析

    #均值:总和/长度 mean() #中位数:将数列排序,若个数为奇数,取排好序数列中间的值.若个数为偶数,取排好序数列中间两个数的平均值 median() #R语言中没有众数函数 #分位数 quant ...

  10. Java-利用spring发送邮件

    最近项目中需要发送邮件的功能,于是百度一大把例子.但是有很多都是一样的,一点特点都没有.所以决定整理一番.         在spring2.X以后的版本就提供了org.springframework ...