Little Zu Chongzhi's Triangles
Little Zu Chongzhi's Triangles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 743 Accepted Submission(s): 399
It is said in some legend story books that when Zu was a little boy, he liked mathematical games. One day, his father gave him some wood sticks as toys. Zu Chongzhi found a interesting problem using them. He wanted to make some triangles by those sticks, and he wanted the total area of all triangles he made to be as large as possible. The rules were :
1) A triangle could only consist of 3 sticks.
2) A triangle's vertexes must be end points of sticks. A triangle's vertex couldn't be in the middle of a stick.
3) Zu didn't have to use all sticks.
Unfortunately, Zu didn't solve that problem because it was an algorithm problem rather than a mathematical problem. You can't solve that problem without a computer if there are too many sticks. So please bring your computer and go back to Zu's time to help him so that maybe you can change the history.
The first line is an integer N(3 <= N<= 12), indicating the number of sticks Zu Chongzhi had got. The second line contains N integers, meaning the length of N sticks. The length of a stick is no more than 100. The input ends with N = 0.
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
using namespace std;
int cmp(int a,int b){
return a>b;
}
double area(int a,int b,int c){
//printf("%d %d %d\n",a,b,c);
double q=(a+b+c)/2.0;
double p;
p=sqrt(1.0*q*(q-a)*(q-b)*(q-c));
return p;
}
int stick[];
int main(){
int N;
while(~scanf("%d",&N),N){
for(int i=;i<N;i++){
scanf("%d",&stick[i]);
}
sort(stick,stick+N,cmp);
double ans=;
for(int i=;i+<N;i++){
if(stick[i+]+stick[i+]>stick[i]){
ans+=area(stick[i],stick[i+],stick[i+]);
i+=;
}
}
printf("%.2lf\n",ans);
}
return ;
}
Little Zu Chongzhi's Triangles的更多相关文章
- hdu5135 Little Zu Chongzhi's Triangles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Total Submissi ...
- [HDU 5135] Little Zu Chongzhi's Triangles (dfs暴搜)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5135 题目大意:给你n条边,选出若干条边,组成若干个三角形,使得面积和最大.输出最大的面积和. 先将边 ...
- UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- hdu 5135 Little Zu Chongzhi's Triangles
http://acm.hdu.edu.cn/showproblem.php?pid=5135 题意:给你N个木棍的长度,然后让你组成三角形,问你组成的三角形的和最大是多少? 思路:先求出可以组成的所有 ...
- UVALive 7077 Little Zu Chongzhi's Triangles (有序序列和三角形的关系)
这个题--我上来就给读错了,我以为最后是一个三角形,一条边可以由多个小棒组成,所以想到了状态压缩各种各样的东西,最后成功了--结果发现样例过不了,三条黑线就在我的脑袋上挂着,改正了以后我发现N非常小, ...
- HDU5131-Song Jiang's rank list HDU5135-Little Zu Chongzhi's Triangles(大佬写的)
Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java ...
- URAL 7077 Little Zu Chongzhi's Triangles(14广州I)
题目传送门 题意:有n根木棍,三根可能能够构成三角形,选出最多的三角形,问最大面积 分析:看到这个数据范围应该想到状压DP,这次我想到了.0010101的状态中,1表示第i根木棍选择,0表示没选,每一 ...
- HDU 5135.Little Zu Chongzhi's Triangles-字符串 (2014ACM/ICPC亚洲区广州站-重现赛)
Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 ...
- HDU5135 dfs搜索 枚举种数
Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 ...
随机推荐
- android透明度和css透明度
值越小,越透明 css:0.1-------1 android:#00-----------#ff
- 【Mysql5.7数据目录和配置文件目录】
Win7下 C:\ProgramData\MySQL\MySQL Server 5.7\ 如何查看mysql运行.访问记录等日志 1.首先确认你日志是否启用了mysql>show variabl ...
- 怎么去掉word标题前的黑点
原文地址:http://jingyan.baidu.com/article/9c69d48f593c5b13c9024e2c.html 我们在使用word时,标题前总是出现黑点,其实这个黑点在打印时是 ...
- hdu 5093 Battle ships 匈牙利 很巧妙的建图思路
//这题逼我把匈牙利学了 之前一直很勤快敲网络流 而且不以为耻反以为荣 解:首先按行扫描编号,如果在同一块中(即可以相互攻击),那么将其标为相同的数组,对列也做同样的操作. 然后扫描整张图,如果行编号 ...
- [Leetcode][Python]51: N-Queens
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 51: N-Queenshttps://oj.leetcode.com/pro ...
- 搭讪培训班 - 名品试用 - YOKA时尚论坛 - YOKA社区
搭讪培训班 - 名品试用 - YOKA时尚论坛 - YOKA社区 搭讪培训班 发贴回复 发新话题 发布投票 搭讪培训班 1330 1 阅读 回复 跳转到指定楼层 加为好友 时尚懒洋洋 工作:无业游 ...
- GDB 多进程调试
启动: $gdb <file> || $gdb 然后(gdb)file <file> 运行: (gdb)run <该程序本身的命令行参数> 查看代码: (gdb) ...
- hdu 2254 奥运(邻接矩阵应用)
Problem Description 北京迎来了第一个奥运会,我们的欢呼声响彻中国大地,所以今年的奥运金牌 day day up! 比尔盖兹坐上鸟巢里,手里摇着小纸扇,看的不亦乐乎,被俺们健儿的顽强 ...
- Stopwatch 类【转】
一般我们想要测试使用那种方法或着那种类型效率更高,使用Stopwatch类进行测试就可以,我也是现在才知道,汗一个. 先来看个小示例,如下. 前提,先引用using System.Diagnostic ...
- 查看当前支持的MySQL字符集的命令
查看不同的MySQL字符集有不同的方法,下面介绍的命令用于查看当前支持的MySQL字符集,希望对您学习MySQL字符集能有所帮助. mysql> show char set; +-------- ...