Triangular Pastures

时间限制(普通/Java):3000MS/10000MS          运行内存限制:65536KByte

描述

Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.

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.

输入

* Line 1: A single integer N
* Lines 2..N+1: N lines, each with a single integer representing one fence segment's length.  The lengths are not necessarily unique.

输出

A single line with the integer that is the truncated integer representation of the largest possible enclosed area multiplied by 100. Output -1 if no triangle of positive area may be constructed.

样例输入

5
1
1
3
3
4

样例输出

692
题目大意:给出n条边,找出可以拼成的一个三角形的最大面积
#include<iostream>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
bool flag[810][810];int main() {int n,i,j,k,ans;int str[110];while(~scanf("%d",&n)) {ans = 0;for(i=1; i<=n; i++) {scanf("%d",&str[i]);ans+=str[i];}memset(flag,false,sizeof(flag));flag[0][0]=true;int mid=ans/2;
     //判断是否可以形成三角形for(i=1; i<=n; i++)for(j=mid; j>=0; j--)for(k=j; k>=0; k--)if(j>=str[i]&&flag[j-str[i]][k] || k>=str[i]&&flag[j][k-str[i]])flag[j][k]=true;int Max=-1;for(i=mid; i>=1; i--)for(j=i; j>=1; j--) {if(flag[i][j]) {k=ans-i-j;if(i+j>k && i+k>j && j+k>i) {double p=(i+j+k)/2.0;int c=(int)(sqrt(p*(p-i)*(p-j)*(p-k))*100);if(c>Max)Max=c;}}}printf("%d\n",Max);}return 0;
}

转载于:https://www.cnblogs.com/lavender913/p/3310813.html

Triangular Pastures相关推荐

  1. Triangular Pastures (二维01背包)

    描述 Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectan ...

  2. 所谓的二维背包Triangular Pastures POJ 1948

    这题WA了很多遍,要不就是测试数据 3 1 2 3 输出173,要不就是6 5 5 5 5 5 5  输出-1.甚至有时候把程序改的题目上的测试数据都过不了,各种悲摧,其实我喜欢边写程序边想,这是个很 ...

  3. POJ 1948 Triangular Pastures (二维01背包)

    题目链接:http://poj.org/problem?id=1948 题目大意:给最多40根木棍,每根长度不超过40,要用完所有的木棍构成面积最大的三角形,求出最大的面积. 思路:设f[i][j]为 ...

  4. DP分类题目 转载 《志当存高远》大神的 没有冒犯的意思 只是拿过来学习的

    A.各种背包,就根据背包九讲的内容来做吧! --不会背包的可以边看背包九讲边练习 =========================================================== ...

  5. 杭电oj题目题型分类(转)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

  6. HDOJ题目分类大全

    版权声明:本文为博主原创文章,欢迎转载,转载请注明本文链接! https://blog.csdn.net/qq_38238041/article/details/78178043 杭电里面有很多题目, ...

  7. HDU题目分类大全【大集合】

    基础题: 1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.  1032.1037.1040.1048.1056.105 ...

  8. POJ的题目分类(两个版本)

    版本一: 简单题 1000A+B Problem 1001Exponentiation 1003 Hangover 1004 Financial Management 1005 I Think I N ...

  9. POJ前面的题目算法思路【转】

    1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...

  10. 杭电OJ题目分类(转载)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

最新文章

  1. CentOS上安装 jdk
  2. php 验证码小写,PHP实现验证码
  3. Maven最佳实践-distributionManagement
  4. 【APUE】孤儿进程与僵死进程
  5. 小数点化分数的过程_分数和小数的互化
  6. 红旗6.0SP2发布啦!
  7. uniapp ---- 添加分页
  8. java基础知识总结(经典)_Java基础知识总结(超级经典)(三)
  9. Java项目:SSM的校园二手交易平台
  10. cmdn(聪明的女人)
  11. 单GPU每秒76帧,重叠对象也能完美分割,多模态Transformer用于视频分割效果惊艳...
  12. 测试系统工程师TSE的四项基本技能
  13. 信号与系统 频域分析
  14. VCC、 VDD、VSS、VEE 电压符号的解释
  15. 漏电继电器LLJ-100FS
  16. kettle效率提升
  17. 设置代理让github加速
  18. 《最强大脑——77招让你成为脑力最好的人》读书笔记
  19. 爬虫基础(6)网页解析之XPath库
  20. php usc2,CSDN 免积分下载原理

热门文章

  1. java连接数据库增删改查公共方法
  2. SDL如何嵌入到QT中?!
  3. Linux下安装zookeeper集群,以及在window用dubbo和代码测试
  4. poj1466二分图
  5. 本人教你五分钟学会五笔(不服找我)
  6. 文件上传------c#
  7. IntelliJ IDEA使用技巧(二)——添加jar包
  8. Python3 - 字符串
  9. h5页面在ios机上禁止长按复制
  10. SpringBoot入门教程(十四)导出Excel