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 ...
随机推荐
- Jquery基础之ajax
ajax是Asynchronous JavaScript and XML(异步JavaScript和XML)的简称,ajax并不是单一的技术而是利用一系列交互网页应用相关的技术形成的结合体,ajax揭 ...
- ui原则
http://www.niushe.com/news/show-3683.html 设计师Joshua Porter发表了一篇文章——<Principles of User Interface ...
- Android实现ListView或GridView首行/尾行距离屏幕边缘距离
直接上关键属性: 设置ListView或GridView的android:clipToPadding = true, 然后通过paddingTop和paddingBottom设置距离就好了.
- java设计模式--行为型模式--命令模式
命令模式 概述 将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化:对请求排队或记录请求日志,以及支持可撤消的操作. 适用性 .抽象出待执行的动作以参数化某对象. .在不同的时刻指定.排 ...
- 杭电oj1236 排名
Tips:此题比较简单,最好将每一个学生的信息构建一个结构体,另外需要注意的是,若分数相同,排序按姓名排序,我看网上很多都是使用<algorithm>中的sort算法,只需重写cmp函数即 ...
- hdu1588之经典矩阵乘法
Gauss Fibonacci Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 5605 geometry(几何,数学)
Problem Description There is a point P at coordinate (x,y). A line goes through the point, and inter ...
- 卸载mysql残留
一.在控制面板中查看是否有mysql,有则进行卸载.或执行同样版本号的mysql安装文件,选择"remove"进行卸载. 二.卸载mysql后其服务仍在,解决的方法: 点击&quo ...
- 移植busybox-1.21.1
busybox官网:www.busybox.net 1.解压 # tar jxvf busybox-1.21.1.tar.bz2 2.配置 # cd busybox-1.21.1 # make men ...
- CF 444A(DZY Loves Physics-低密度脂蛋白诱导子图)
A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard ...