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: ...
随机推荐
- mybatis缓存的设计
继续用提问的方式来看Mybatis的缓存设计. 1.Mybatis如何开启缓存 Mybatis对查询结果进行缓存,所以缓存的对象为具体的Statement 通过在Statement上是否使用缓存来启用 ...
- 命令纠正工具 thefuck 的简单使用
在unix系列的系统中,总会出现 命令拼写或者执行错误的情况, 比如 把 python 写成了pythou, cd 到一个不存在的目录,执行任务的权限 不够的问题, 这是心里 总是 在 fuck,但是 ...
- spring boot 监听器实例
在日常项目中订单创建成功后,会有类似各式各样的通知.有站内通知.短信通知.微信,app通知. 伪代码: 这里,只用伪代码示例.各式各样的通知 肯定不只一行代码.只是简化.如果后续还要增加各种各样的通知 ...
- jinja2 把文本变成html
data 是传过去的值 过滤器 | {{data.name | safe}}
- ATS6.2安装部署笔记
原文:http://www.safecdn.cn/ats/2018/12/ats6-2-install/1046.html 系统版本:CentOS 6.7 1.安装依赖包 yum -y install ...
- ECharts教程
ECharts 特性 兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Firefox,Safari等) 底层依赖轻量级的矢量图形库 ZRender 丰富的可视化类型 常规的折线图.柱状图 ...
- 使用 nodeJs 开发微信公众号(设置自动回复消息)
微信向第三方服务器发送请求时会降 signature .timestamp. nonce . openid(用户标识),发送内容会以 xml 的形式附加在请求中 回复消息前提我们得拿到用户id , 用 ...
- 【转】STM32 不占用定时器(包括SysTick)实现精确延时(巧用DWT)
/** ****************************************************************** * file core_delay.c * author ...
- pyqt------对话框
一 .输入文字 from PyQt5.QtWidgets import (QWidget, QPushButton, QLineEdit, QInputDialog, QApplication) im ...
- sql存储过程调用示例
1.配置文件: <connectionStrings> <add name="constr" connectionString="data source ...