Triangular Pastures
2013-09-09 20:44
232 查看
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; }
相关文章推荐
- angularjs DI简单模拟
- ie style 不支持 angular expression
- Problem 12:Highly divisible triangular number
- angularJS之基础知识(三)
- poj 1948 Triangular Pastures 二维01背包
- angularJS之基础知识(二)
- 有jQuery背景的我,该如何用AngularJS编程思想?
- angularJS之基础知识(一)
- 用AngularJS减少代码量吧
- angular 使用过程中遇到的问题
- AngularJS开发经验
- angularjs跨window controller互操作的方法
- Angularjs系列之表单验证
- POJ 1948 Triangular Pastures 二维 0-1背包
- AngularJs+bootstrap搭载前台框架——js控制部分
- AngularJs数据绑定原理
- 使用Yeoman快速构建基于angular的web应用
- 使用Yeoman快速构建基于angular的web应用
- AngularJs part1
- C 语言 南阳理工ACM 122.Triangular Sums