描述

Did you ever wonder what happens to your money when you deposit them to a bank account? All banks hold such deposits in various assets, such as gold, stocks, obligations, deposits in other banks, loans, bonds, and many others. Due to the financial crisis and instability of the stock exchanges, many banks find out that stocks are not very reliable and their possession may be too risky.

Therefore, the banks now prefer other assets, especially gold. The main trouble with gold is that there is only a limited amount of it in the whole world. And it is not enough to cover all money held by all banks. (Wait, isn't this the real reason of the crisis?)

If there is not enough gold, other commodities must be exploited instead. The International Bank of Monetania (IBM) has recently come up with an idea of using very old and valuable trees as their assets. They bought a piece of land with several such trees and now expect their value to grow. Literally, of course.

Unfortunately, the trees are threatened by wildlife, because animals do not understand their value and nibble them. Moreover, there is a permanent danger of theft. As a result, it is absolutely necessary to build a good solid fence around the trees.

The IBM quickly realized that the only suitable material available to build the fence is the wood from the trees themselves. In other words, it is necessary to cut down some trees in order to build a fence around the remaining ones. Of course, to keep the maximum value, we want to minimize the value of the trees that had to be cut. You are to write a program that solves this problem.

输入

The input contains several test cases, each of which describes one piece of land. Each test case begins with a line containing a single integer N, 2 ≤ N≤ 16, the total number of trees. Each of the subsequent N lines contains 4 integers Xi, Yi, Vi, Li separated by at least one space.

The four numbers describe a single tree. (Xi, Yi) is the position of the tree in the plane, Vi is its value, and Li is the length of fence that can be built using the wood of the tree. You may assume that 0 ≤ Vi, Li ≤ 10000 and -10000 ≤ Xi, Yi ≤ 10000. No two trees in a test case will grow at the same position.

The input ends with a line containing zero in place of N.

输出

For each test case, compute a subset of the trees such that, using the wood from that subset, the remaining trees can be enclosed in a single continuous fence. Find the subset with the minimal total value. For simplicity, regard the trees as having zero diameter.

Output one line with the sentence "The lost value is T.", where T is the minimal value of the trees that must be cut.

样例输入

6
0 0 8 3
1 4 3 2
2 1 7 1
4 1 2 3
3 5 4 6
2 3 9 8
3
3 0 10 3
5 -3 20 25
7 -3 30 32
2
100 0 5 4
0 100 4 5
5
0 0 10 10
0 1 10 10
1 0 10 10
1 1 10 10
50 50 8 4
0

样例输出

The lost value is 9.
The lost value is 20.
The lost value is 4.
The lost value is 8.

题意

N棵树位置(X,Y)价值V长度L,要求砍伐的树价值最小并且总长度能围住剩下的树

题解

暴力凸包求周长,复杂度O(2^N*NlogN)

代码

 #include<bits/stdc++.h>
using namespace std; struct Point{
double x,y,V,L;
}d[],p[];
double dis(Point p1,Point p2){return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}
double xmulti(Point p1,Point p2,Point p0){return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}
double graham(int n)
{
int pl[],t=,num=;
for(int i=;i<=n;i++)if(p[i].y<p[t].y)t=i;
pl[]=t;
do
{
num++;
t=pl[num-]+;
if(t>n)t=;
for(int i=;i<=n;i++)
{
double x=xmulti(p[i],p[t],p[pl[num-]]);
if(x<)t=i;
}
pl[num]=t;
}while(pl[num]!=pl[]);
double sum=;
for(int i=;i<num;i++)
sum+=dis(p[pl[i]],p[pl[i+]]);
return sum;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF,n)
{
double minn=;
for(int i=;i<n;i++)scanf("%lf%lf%lf%lf",&d[i].x,&d[i].y,&d[i].V,&d[i].L),minn+=d[i].V;
int state=<<n;
for(int i=;i<state;i++)
{
int sxV=,sxL=,pos=;
for(int j=;j<n;j++)
{
if((i&(<<j))==)sxV+=d[j].V,sxL+=d[j].L;
else p[++pos]=d[j];
}
if(minn>sxV&&graham(pos)<=sxL)minn=sxV;
}
printf("The lost value is %.0f.\n",minn);
}
return ;
}

TZOJ 2569 Wooden Fence(凸包求周长)的更多相关文章

  1. zoj 1453 Surround the Trees(凸包求周长)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds      Memory ...

  2. hdu 1348 (凸包求周长)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  3. POJ 1113 Wall 凸包求周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26286   Accepted: 8760 Description ...

  4. Surround the Trees(凸包求周长)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  5. HDU - 1392 凸包求周长(模板题)【Andrew】

    <题目链接> 题目大意: 给出一些点,让你求出将这些点全部围住需要的多长的绳子. Andrew算法 #include<iostream> #include<cstdio& ...

  6. HDU 4667 Building Fence(求凸包的周长)

    A - Building Fence Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u ...

  7. (hdu step 7.1.7)Wall(求凸包的周长——求将全部点围起来的最小凸多边形的周长)

    题目: Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  8. HDU1392Surround the Trees(凸包判断 + 求周长)

    http://www.cnblogs.com/hmhard/archive/2013/02/05/2893035.html 这是判断三角区域那块写的不好. 判断凸包的方法: 1.将所有点按照y从小到大 ...

  9. poj 3348--Cows(凸包求面积)

    链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:  ...

随机推荐

  1. YAML快速入门

    https://www.jianshu.com/p/97222440cd08 我们学习Java,都是先介绍properties文件,使用properties文件配合Properties对象能够很方便的 ...

  2. 通过jedis远程访问redis服务器

    一.jedis简介 类似于mysql数据库,一般开发都需要通过代码去访问redis服务器,对于主流的开发语言,redis提供了访问的客户端接口. https://redis.io/clients 而对 ...

  3. c#判断字符串是否为空或null

    通常有: string str=""; .if(str=="") .if(str==String.Empty) .) 三种方法的效果一样,都可以判断字符串是否为 ...

  4. altium designer 制作内部不铺铜的封装,如三极管下面禁止铺铜

    制作封装的时候,按P键或菜单栏中点击place选项点选Polygon Pour Cutout.画一个原件禁止铺铜区域即可.

  5. Spark RDD 操作

    1. Spark RDD 创建操作 1.1 数据集合   parallelize 可以创建一个能够并行操作的RDD.其函数定义如下: ) scala> sc.defaultParallelism ...

  6. ubuntu16安装dhcp server

    目录 操作命令 apt-get install -y isc-dhcp-server vi /etc/default/isc-dhcp-server 我的修改内容为INTERFACES="e ...

  7. DocKer 创建容器 镜像端口映射失败

    问题一: 我想使用同一个镜像创建多个容器,并映射端口出现以下错误,该怎么解决? docker: Error response from daemon: driver failed programmin ...

  8. mybaties插件生成代码

    指定插件运行什么xml,关于如何用idea创建一个maven项目,可以看我以前写的博客 <?xml version="1.0" encoding="UTF-8&qu ...

  9. 列举spark所有算子

    一.RDD概述      1.什么是RDD           RDD(Resilient Distributed Dataset)叫做弹性分布式数据集,是Spark中最基本的数据抽象,它代表一个不可 ...

  10. Git的操作理解

    1.本地和远程的关系相当于两个分支,是相互独立的. 2.本地分支属于本地仓库,一个仓库可以包含多个分支. 3.commit是为了告诉Git这次提交我改了哪些东西:       pull是将远程comm ...