描述

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. Java邮件发送

    Java中发送邮件的方法之一,需要用到spring框架集成的JavaMailSenderImpl.SimpleMailMessage两个实现类. 一,创建一个service,代码如下: public ...

  2. Difference between hash() and id()

    https://stackoverflow.com/questions/34402522/difference-between-hash-and-id There are three concepts ...

  3. python守护进程

    1.守护进程 [1]使用runner这个模块直接创建守护进程,非常方便. [2]运行方法:python xxx.py start|stop|restart [3]调用python xxx.py sto ...

  4. 机器学习笔记之三-yolov3+win7+vs2017+gpu+opencv编译

    1.环境安装 1.1 vs2017+cuda9.1+cudnn7.0可以和tensorflow一起安装网上教程多,不多说.       唯一需要注意的是vs2017要安装好2015版本的工具集v140 ...

  5. c#+CAD动态移动效果

    public class MoveRotateScaleJig : DrawJig { public static List<Entity> entities = new List< ...

  6. nginx+多个tomcat

    学习nginx的时候遇到的问题:nginx怎么部署两台tomcat?   upstream 在网上找的资源,我在nginx配置文件(nginx.conf)中添加了两个server.结果只显示第一个se ...

  7. docker镜像的常用操作

    获取镜像 比如说我们可以这样操作 当然把这个镜像拉过来时间非常长.   查看镜像列表 命令: docker images 说明: 使用docker images命令可以列出本地主机上已有的镜像. 信息 ...

  8. 三、CSS样式——文本

    CSS文本 概念:CSS文本属性可定义文本外观 通过文本属性,可以改变文本的颜色.字符间距.对齐文本.装饰文本.对文本缩进 属性 描述 color 文本颜色 direction 文本方向 line-h ...

  9. sql语句case when 以及left()

    select count(CASE jyje WHEN '1300' THEN '2' ELSE '1' END) as count  from tpent_orders where cplx = 6 ...

  10. Spring 回滚事务@Transactional

    @Transactional   spring 事务注解 默认遇到throw new RuntimeException("...");会回滚 需要捕获的throw new Exce ...