描述

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)

代码

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 struct Point{
 5     double x,y,V,L;
 6 }d[17],p[17];
 7 double dis(Point p1,Point p2){return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}
 8 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);}
 9 double graham(int n)
10 {
11     int pl[17],t=1,num=1;
12     for(int i=1;i<=n;i++)if(p[i].y<p[t].y)t=i;
13     pl[1]=t;
14     do
15     {
16         num++;
17         t=pl[num-1]+1;
18         if(t>n)t=1;
19         for(int i=1;i<=n;i++)
20         {
21             double x=xmulti(p[i],p[t],p[pl[num-1]]);
22             if(x<0)t=i;
23         }
24         pl[num]=t;
25     }while(pl[num]!=pl[1]);
26     double sum=0;
27     for(int i=1;i<num;i++)
28         sum+=dis(p[pl[i]],p[pl[i+1]]);
29     return sum;
30 }
31 int main()
32 {
33     int n;
34     while(scanf("%d",&n)!=EOF,n)
35     {
36         double minn=0;
37         for(int i=0;i<n;i++)scanf("%lf%lf%lf%lf",&d[i].x,&d[i].y,&d[i].V,&d[i].L),minn+=d[i].V;
38         int state=1<<n;
39         for(int i=0;i<state;i++)
40         {
41             int sxV=0,sxL=0,pos=0;
42             for(int j=0;j<n;j++)
43             {
44                 if((i&(1<<j))==0)sxV+=d[j].V,sxL+=d[j].L;
45                 else p[++pos]=d[j];
46             }
47             if(minn>sxV&&graham(pos)<=sxL)minn=sxV;
48         }
49         printf("The lost value is %.0f.\n",minn);
50     }
51     return 0;
52 }

转载于:https://www.cnblogs.com/taozi1115402474/p/10374131.html

TZOJ 2569 Wooden Fence(凸包求周长)相关推荐

  1. HDU1392(凸包求周长模版)

    其实这个求凸包周长也算是模版. #include<iostream> #include<algorithm> #include<cstring> #include& ...

  2. 二维凸包(模板) hdu 1348 求凸包的周长

    题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1348 凸包模板: const int N =1010; const double PI = 3.141 ...

  3. java里创建一个长方形类_定义一个长方形类,定义 求周长和面积的方法实例

    /* 定义一个长方形类,定义 求周长和面积的方法, 然后定义一个测试了Test2,进行测试. 长方形的类: 成员变量: 长,宽 成员方法: 求周长:(长+宽)*2; 求面积:长*宽 注意: impor ...

  4. 定义一个长方形类,求周长和面积--学习笔记--16

    1.变量什么时候定义为成员变量 如果这个变量是用来描述这个类的信息的,那么,该变量就应该定义为成员变量 2.变量的范围越小越好,因为能及时的被回收 3.定义一个长方形类,求周长和面积 然后定义一个Te ...

  5. 定义一个长方形类,定义 求周长和面积的方法,然后定义一个测试了Test,进行测试

    定义一个长方形类,定义 求周长和面积的方法,然后定义一个测试了Test,进行测试. import java.util.Scanner; class ChangFangXing{private int ...

  6. 设计一个抽象类图形类,在该类中包含有至少两个抽象方法求周长和求面积,分别定义圆形类、长方形类、正方形类、三角形类来继承图形类,并实现上述两个方法

    设计一个抽象类图形类,在该类中包含有至少两个抽象方法求周长和求面积,分别定义圆形类.长方形类.正方形类.三角形类来继承图形类,并实现上述两个方法 设计抽象类 就要使用abstract关键字,抽象类中的 ...

  7. Java6面向对象编程创建一个矩形类, 求周长 面积

    package job; /** */ import java.util.Scanner; public class Space { /* 面向对象编程创建一个矩形类, 求周长 面积 */ publi ...

  8. 定义一个长方形类,定义 求周长和面积的方法,然后定义一个测试了Test2,进行测试

    /* 定义一个长方形类,定义 求周长和面积的方法, 然后定义一个测试了Test2,进行测试. 长方形的类: 成员变量: 长,宽 成员方法: 求周长:(长+宽)*2; 求面积:长*宽 注意: impor ...

  9. 1.设计一个长方形的类,成员变量有长与宽,成员函数有求周长与面积,然后进行测试。要求有构造函数、析造函数和复制构造函数。

    1.设计一个长方形的类,成员变量有长与宽,成员函数有求周长与面积,然后进行测试.要求有构造函数.析造函数和复制构造函数. 代码比较简单,论坛有坛友问,顺手写一下当复习 #include <bit ...

最新文章

  1. 某个第三方支付平台数据库的分析、学习与总结(转)
  2. Zookeeper配置文件中的配置项解释和Zookeeper的安装
  3. 20321关系数据库理论基础
  4. 字符编码、常见字符集解析(ASCII、Unicode、UTF-8、GB2312等)
  5. java 大小固定_为什么Java堆的最大大小是固定的?
  6. python元祖封包_[Day8]遷延蹉跎,來日無多-python終極指南:模組和封包,外掛般的超能力...
  7. 离线安装mysql5.6及依赖_Linux离线安装mysql 5.6详细步骤
  8. JAVA费罗切测评_暴力美学的终极形态 JAVA Feroce 2评测
  9. 线程---pthread_creat的问题
  10. Java格式化SQL语句
  11. 学习编程的心得(一)
  12. NES模拟器源码阅读
  13. 基于Keilv5新建STM32F030工程
  14. C# CSharp计算标准偏差 重复精度 和Excel中的STDEV函数相同
  15. 十个前端程序员必备的网站
  16. 对于有关串口通信的clk的解释
  17. Excel 2019:二级级联下拉框设置
  18. 二进制、八进制、十进制和十六进制的转换
  19. 苹果新规,微信面临下架?一文看懂苹果与腾讯“相亲相爱相杀”
  20. struts2中如何使用servlet

热门文章

  1. python训练营免费领取-21天训练营丨Python量化投资打卡第五期!学完押金全返!...
  2. 学会python能找工作吗-Python学到什么程度才可以去找工作?掌握这4点足够了!...
  3. python3.6安装-python3.6的安装及注意事项
  4. python有道翻译-使用python2爬取有道翻译
  5. python有趣的小项目-这10个Python项目超有趣!
  6. 计算机二级python用什么书-如何准备全国计算机二级Python?
  7. python 编程一日一练-python每日一练
  8. python系统-Python(第八课,简单开发系统)
  9. python代码编辑器排行榜-4款好用的Python编辑器,你用过几个?
  10. python经典好书-python经典书籍推荐