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 ...
随机推荐
- HourRank 20
第一题略 第二题组合数学 s1 = min(cnt['a'],cnt['b']), s2 = min(cnt['c'],cnt['d']), b1 = max(cnt['a'],cnt['b']), ...
- struts2.1.6教程一、准备工作及实例
1.解压struts-2.1.6-all.zip apps目录:struts2自带的例子程序 docs目录:官方文档. lib 目录:存放所有jar文件. Src 目录:源文%件存放地 2.六个基本包 ...
- JS 一条原型链扯到底
在正文之前,首先要知道两点, 1.__proto__是每个js 对象的内置属性,而prototype 是函数的内置属性,也是一个对象. 2.所谓原型,指的就是每个函数对象的prototype属性. f ...
- Openstack虚拟机在线迁移(Live Migration)
Openstack VM live migration can have 3 categories: -Block live migration without shared storage -Sha ...
- DelayQueue使用
假设现有如下的使用场景: a) 关闭空闲连接.服务器中,有很多客户端的连接,空闲一段时间之后需要关闭之. b) 缓存.缓存中的对象,超过了空闲时间,需要从缓存中移出. c) 任务超时处理.在网络协议滑 ...
- mysql5.6 rpm安装配置
检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称) [root@localhost share]# rpm -qa | grep -i mysql MySQL-cli ...
- php笔记一
一.Login登陆验证步骤: 1.赋值,用$_POST将id和password传递给loginProcess.php登陆验证页面. 2.建立数据库连接 $conn=mysql_connect($hos ...
- Hybrid App开发之JavaScript基础
前言: 前面学习了html和css的基本使用,今天开始学习JavaScript的使用. 什么是JavaScript JavaScript是一种基于对象(Object)和事件驱动(Event Drive ...
- 并发容器ConcurrentHashMap#put方法解析
jdk1.7.0_79 HashMap可以说是每个Java程序员用的最多的数据结构之一了,无处不见它的身影.关于HashMap,通常也能说出它不是线程安全的.这篇文章要提到的是在多线程并发环境下的Ha ...
- threading多线程总结
threading用于提供线程相关的操作,线程是应用程序中工作的最小单元.python当前版本的多线程库没有实现优先级.线程组,线程也不能被停止.暂停.恢复.中断. threading模块提供的类: ...