poj 1948 Triangular Pastures 小结
Description
I. M. Hei, the lead cow pasture architect, is in charge of creating a triangular pasture surrounded by nice white fence rails. She is supplied with N (3 <= N <= 40) fence segments (each of integer length Li (1 <= Li <= 40) and must arrange them into a triangular
pasture with the largest grazing area. Ms. Hei must use all the rails to create three sides of non-zero length.
Help Ms. Hei convince the rest of the herd that plenty of grazing land will be available.Calculate the largest area that may be enclosed with a supplied set of fence segments.
Input
* Lines 2..N+1: N lines, each with a single integer representing one fence segment's length. The lengths are not necessarily unique.
Output
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;double ans;
long now,i,j,k,sum,len=0,n,a[41];
bool f[1601][1601];
double count(long x,long y)
{
long z=len-x-y;
if (x+y<=z&&x+z<=y&&y+z<=x) return 0;
double p=(x+y+z)*1.0/2;
return (sqrt(p*(p-x)*(p-y)*(p-z)));
}
int main()
{
//freopen("pasture.in","r",stdin);
//freopen("pasture.out","w",stdout);
scanf("%ld",&n);
for (i=1;i<=n;i++)
{
scanf("%ld",&a[i]);
len+=a[i];
}
memset(f,0,sizeof(f));
f[0][0]=true;sum=0;ans=0;
for (i=1;i<=n;i++)
{
for (j=sum;j>=0;j--)
for (k=sum;k>=0;k--)
if (f[j][k])
{
f[j+a[i]][k]=true;
f[j][k+a[i]]=true;
}
sum+=a[i];
}
for (i=1;i<=sum;i++)
for (j=1;j<=sum;j++)
if (f[i][j])
{
ans=max(ans,count(i,j));
}
now=long(ans*100);
if (now==0) printf("-1");
else printf("%ld",now);
//scanf("%ld",&n);
return 0;
}
poj 1948 Triangular Pastures 小结的更多相关文章
- [POJ] 1948 Triangular Pastures (DP)
题目地址:http://poj.org/problem?id=1948 题目大意: 给N条边,把这些边组成一个三角形,问面积最大是多少?必须把所有边都用上. 解题思路: 根据题意周长c已知,求组合三边 ...
- POJ 1948 Triangular Pastures【二维01背包】
题意:给出n条边,用这n条边构成一个三角形,求三角形的最大面积. 先求面积,用海伦公式,s=sqrt(p*(p-a)*(p-b)*(p-c)),其中a,b,c分别为三角形的三条边,p为三角形的半周长, ...
- POJ 1948 Triangular Pastures
题意: 把很多单独的线段重新组合成一个三角形,使得三角形面积最大(所有的线段都必须用上). 思路: 三角形的任意一条边的边长不能超过周长的一半,只需要用dp枚举两条边j,k,剩下的一条边长为tot ...
- Triangular Pastures POJ - 1948
Triangular Pastures POJ - 1948 sum表示木条的总长.a[i]表示第i根木条长度.ans[i][j][k]表示用前i条木条,摆成两条长度分别为j和k的边是否可能. 那么a ...
- POJ1948 Triangular Pastures
POJ1948 Triangular Pastures #include <iostream> #include <cmath> using namespace std; ; ...
- Triangular Pastures (二维01背包)
描述Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectang ...
- POJ 3086 Triangular Sums (ZOJ 2773)
http://poj.org/problem?id=3086 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1773 让你计算两 ...
- poj 1948二维01背包
题意:给出不多于40个小棍的长度,求出用所有小棍组成的三角形的最大面积. 思路:三角形3边求面积,海伦公式:p=(a+b+c)/2;S=p*(p-a)*(p-b)*(p-c);因为最大周长为1600 ...
- POJ - 1948 二维01背包
T了两发,DP方程很简单粗暴 dp[i][j][k]:用前i物品使得容量分别为j和k的背包恰好装满 背包的调用只需一次即可,第一次T就是每次check都丧心病狂地背包一次 对于sum的枚举,其实i j ...
随机推荐
- java中为什么实体类需要实现序列化
当客户端访问某个能开启会话功能的资源,web服务器就会创建一个HTTPSession对象,每个HTTPSession对象都会占用一定的内存,如果在同一个时间段内访问的用户太多,就会消耗大量的服务器内存 ...
- [原创]MySQL数据库忘记root密码解决办法
MySQL数据库忘记root密码解决办法 1.在运行输入services.msc打开服务窗体,找到MYSQL服务.右键停止将其关闭.如图:
- centos7.2下编译安装apache2.4
1.安装编译工具 [root@carl httpd-2.4.25]# yum groupinstall 'Development Tools' 'Server Platform Development ...
- 【知识整理】惊现RecyclerView内部Bug???别急,我们慢慢解决它~
一.写在前面 这也是久违的一整个月没有写Blog,也是由于近期给妹纸找工作,各种坑蒙拐骗,然而都没卵用.额,广大朋友们,成都需要软件测试.线上运维.产品助理的伙伴,赶紧私聊我了.这妹纸,学习能力挺好, ...
- 【Spark2.0源码学习】-10.Task执行与回馈
通过上一节内容,DriverEndpoint最终生成多个可执行的TaskDescription对象,并向各个ExecutorEndpoint发送LaunchTask指令,本节内容将关注Exe ...
- Linux安装JDK完整步骤
1.检查一下系统中的jdk版本 [root@localhost software]# java -version 显示: openjdk version "1.8.0_102" O ...
- iOS gcd 串行,并行,同步,异步代码研究
参考文章: p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #527eff } span.s1 { } http: ...
- AngularJS高级程序设计读书笔记 -- 指令篇 之 内置指令
1. 内置指令(10-12 章) AngularJS 内置超过 50 个内置指令, 包括 数据绑定,表单验证,模板生成,时间处理 和 HTML 操作. 指令暴露了 AngularJS 的核心功能, 如 ...
- ⑨的完美冻青蛙(frog)
⑨的完美冻青蛙(frog) 时间限制: 1 Sec 内存限制: 128 MB 题目描述 输入 第一行是一个正整数n,表示上式中的p的个数. 接下来有n行,每一行两个正整数pi 和ei . 输出 ...
- CYQ.Data V5 分布式自动化缓存设计介绍(二)
前言: 最近一段时间,开始了<IT连>创业,所以精力和写的文章多数是在分享创业的过程. 而关于本人三大框架CYQ.Data.Aries.Taurus.MVC的相关文章,基本都很少写了. 但 ...