TZOJ 2569 Wooden Fence(凸包求周长)
描述
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(凸包求周长)的更多相关文章
- zoj 1453 Surround the Trees(凸包求周长)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds Memory ...
- hdu 1348 (凸包求周长)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others) Mem ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
- Surround the Trees(凸包求周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU - 1392 凸包求周长(模板题)【Andrew】
<题目链接> 题目大意: 给出一些点,让你求出将这些点全部围住需要的多长的绳子. Andrew算法 #include<iostream> #include<cstdio& ...
- HDU 4667 Building Fence(求凸包的周长)
A - Building Fence Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%I64d & %I64u ...
- (hdu step 7.1.7)Wall(求凸包的周长——求将全部点围起来的最小凸多边形的周长)
题目: Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- HDU1392Surround the Trees(凸包判断 + 求周长)
http://www.cnblogs.com/hmhard/archive/2013/02/05/2893035.html 这是判断三角区域那块写的不好. 判断凸包的方法: 1.将所有点按照y从小到大 ...
- poj 3348--Cows(凸包求面积)
链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: ...
随机推荐
- CentOS7的内核优化
修改内核配置文件 vim /etc/sysctl.conf 刷新配置文件 sysctl -p 关ipv6 net.ipv6.conf.all.disable_ipv6 = net.ipv6.conf. ...
- python,运算符,基本数据类型
a = 'py' in 'python' b = 'py' not in 'python' print(a)print(b) in :判断一个前面一个字符串中的字符是否完整的出现在后面的字符串中,如果 ...
- 2018-2019-2 20165205 《网络对抗技术》 Exp1 PC平台逆向破解
2018-2019-2 20165205 <网络对抗技术> Exp1 PC平台逆向破解 1. 实验任务 1.1实验概括 用一个pwn1文件. 该程序正常执行流程是:main调用foo函数, ...
- mysql 关联
自关联 设计省信息的表结构provinces id ptitle 设计市信息的表结构cityscitys表的proid表示城市所属的省,对应着provinces表的id值 id ctitle proi ...
- command not found所有执行命令总是报找不到
输入 ll命令 提示: bash: ls: 未找到命令… 相似命令是: 'lz' 原因: 环境变量PATH被修改了 解决办法: 执行: export PATH=/bin:/usr/bin:$PATH ...
- python———day01
一.变量命名规则: 1,要有描述性: 2,变量名只能以 下划线,数字,字母组成,不可以有特殊符号和空格: 3,不能以中文为变量名(规范): 4,不能以数字开头: 5,保留字符(即关键字:如print ...
- VM下安装Windows 2008 R2服务器操作系统
打开虚拟机,双击双击新的虚拟机. 2 硬件兼容性选择workstation10.点击下一步. 3 选择我以后安装操作系统.点击继续 4 选择Microsoft windows,版本为windows s ...
- nginx的命令
- JeeWx全新版本发布!捷微二代微信活动平台1.0发布!活动插件持续开源更新!
JeeWx捷微二代微信活动平台 (专业微信营销活动平台,活动插件持续更新ing~) 终于等到你!还好我没放弃! 在团队持续多年的努力下,Jeewx微信管家和H5活动平台不断更新迭代,积累了许许多 ...
- JavaScript字符串操作方法大全,包含ES6方法
一.charAt() 返回在指定位置的字符. var str="abc" console.log(str.charAt(0))//a 二.charCodeAt() 返回在指定的位置 ...