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

Problem Description
Zu Chongzhi (429–500) was a prominent Chinese mathematician and astronomer during the Liu Song and Southern Qi Dynasties. Zu calculated the value ofπ to the precision of six decimal places and for a thousand years thereafter no subsequent mathematician computed a value this precise. Zu calculated one year as 365.24281481 days, which is very close to 365.24219878 days as we know today. He also worked on deducing the formula for the volume of a sphere.

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.

 
Input
There are no more than 10 test cases. For each case:

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.

 
Output
For each test case, output the maximum total area of triangles Zu could make. Round the result to 2 digits after decimal point. If Zu couldn't make any triangle, print 0.00 .
 
Sample Input
3 1 1 20 7 3 4 5 3 4 5 90 0
 
Sample Output
0.00 13.64
 题解:写了一下午,醉了,刚开始考虑的太复杂。。。竟然直接想到神搜。。。其实这个题直接从大到小排序,因为每次的三个边都是最大的,所以面积肯定也是最大,从大到小排序又保证了两条小边相加的问题。。。如此简单的一道题考虑的如此复杂,也是醉了,死胡同中漫步。。。。
代码:
 #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的更多相关文章

  1. hdu5135 Little Zu Chongzhi's Triangles

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submissi ...

  2. [HDU 5135] Little Zu Chongzhi's Triangles (dfs暴搜)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5135 题目大意:给你n条边,选出若干条边,组成若干个三角形,使得面积和最大.输出最大的面积和. 先将边 ...

  3. UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  4. hdu 5135 Little Zu Chongzhi's Triangles

    http://acm.hdu.edu.cn/showproblem.php?pid=5135 题意:给你N个木棍的长度,然后让你组成三角形,问你组成的三角形的和最大是多少? 思路:先求出可以组成的所有 ...

  5. UVALive 7077 Little Zu Chongzhi's Triangles (有序序列和三角形的关系)

    这个题--我上来就给读错了,我以为最后是一个三角形,一条边可以由多个小棒组成,所以想到了状态压缩各种各样的东西,最后成功了--结果发现样例过不了,三条黑线就在我的脑袋上挂着,改正了以后我发现N非常小, ...

  6. 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 ...

  7. URAL 7077 Little Zu Chongzhi's Triangles(14广州I)

    题目传送门 题意:有n根木棍,三根可能能够构成三角形,选出最多的三角形,问最大面积 分析:看到这个数据范围应该想到状压DP,这次我想到了.0010101的状态中,1表示第i根木棍选择,0表示没选,每一 ...

  8. 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 ...

  9. HDU5135 dfs搜索 枚举种数

    Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 ...

随机推荐

  1. hdu 1754 I Hate It_线段树

    题意:略 思路:套hdu1166模版改改就行了,要注意的是,网上有的代码是错的,还贴出来... #include <iostream> #include<cstdio> #in ...

  2. 全国计算机等级考试二级教程-C语言程序设计_第2章_C程序设计的初步知识

    正负号与被除数一致. 3 % (-5) == 3 (-3) % 5 == -3 不用求余运算符,求出余数. int x, y; 答:x - x / y * y; const int i = 10; c ...

  3. jsp验证码页面笔记

    首先在网上搜了下jsp生成验证码的代码,如下: package com.servlet; import java.awt.Color; import java.awt.Font; import jav ...

  4. mysql启动报错:Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist

    mysql在首次启动的时候可能会报错:Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist 这时候可以执行脚本 ...

  5. Mysql安装时出现APPLY security settings错误

    在安装mysql数据库时,如果重新安装,很容易遇见apply security setting error(access denied for user 'root@localhost'(using  ...

  6. T-SQL事务

    事务 订火车票的时候,下一个订单,这个订单中,包含多个购买信息,要么全部执行,要么全部不执行,合作事务就是来处理这种模型的一种机制. --关键字:transaction 或 tran 简写形式 --开 ...

  7. MVC 5 + EF 6

    (一) ??运算符 C#中两个问号(“?”)的作用是判断“?”左边的对象是否为null,如果不为null则使用“?”左边的对象,如果为null则使用“?”右边的对象. (二)VS安装Entity Fr ...

  8. C#4 for循环 迭代法 穷举法应用

    for()循环. 四要素: 初始条件,循环条件,状态改变,循环体. 执行过程: 初始条件--循环条件--循环体--状态改变--循环条件.... 注意:for的小括号里面分号隔开,for的小括号后不要加 ...

  9. mysql5 乱码问题解决方案

    今天在写项目时碰到了mysql数据库数据乱码的问题,也从网上查了很多方法,前后折腾了两个小时才终于调整好.现在就把调整过程中碰到的一些问题记录下来: 1.项目是SSH架构,一开始我以为是调用hiber ...

  10. jquery 实现导航栏滑动效果

    精简的代码实现导航栏滑动效果,实现详解: 1.滑块位置:通过父节点position=fixed,子节点position=absolute方式,实现子节点浮动: 2.导航栏居中:通过left=0px,r ...