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 ...
随机推荐
- PowerDesigner15在生成SQL时报错Generation aborted due to errors detected during the verification of the mod
转载: http://blog.csdn.net/successful555/article/details/7582154 PowerDesigner中如何设置字符编码为GBK或者GB2312 ht ...
- Unix/Linux环境C编程入门教程(28) 日期时间那些事儿
记得这个专题第一篇我们写过一个程序运行时间的程序,采用库函数提供的clock()模拟做程序测试.本篇介绍的函数也是和时间相关,但是没有clock的细致,而是提供的系统时间和日期. 1.asctime( ...
- firebug加载不了js脚本文件问题
转载自:http://tieba.baidu.com/p/1008322286 现象: 页面中有加载js文件,但是firebug却提示: 本页面不包含 Javascript 如果 <scr ...
- 【HDU 4786 Fibonacci Tree】最小生成树
一个由n个顶点m条边(可能有重边)构成的无向图(可能不连通),每条边的权值不是0就是1. 给出n.m和每条边的权值,问是否存在生成树,其边权值和为fibonacci数集合{1,2,3,5,8...}中 ...
- Linux启动新进程的几种方法及比较
有时候,我们需要在自己的程序(进程)中启动另一个程序(进程)来帮助我们完成一些工作,那么我们需要怎么才能在自己的进程中启动其他的进程呢?在Linux中提供了不少的方法来实现这一点,下面就来介绍一个这些 ...
- 聚类算法初探(四)K-means
最近由于工作需要,对聚类算法做了一些相关的调研.现将搜集到的资料和自己对算法的一些理解整理如下,供大家参考. 另外在算法代码方面,我也做了一些实现(包括串行和并行),欢迎感兴趣的朋友探讨和交流. 第一 ...
- centos6.2+nginx-1.2.3+php-5.3.17安装脚本
#!/bin/bash # # vm test install script # # create by xk # # data 2013-04-25 # # SOFTPATH=/home/tools ...
- barManager.Menu(barSubItem)
DevExpress 的帮助文档是在太缺乏了,他自己的帮助只有简单描述,没有样例,而它的网站上的在线帮助只有利用它的设计器设计的ToolBar.PopupMenu ,没有利用代码开发的.虽然要利用代码 ...
- Linux学习3——磁盘文件管理系统与压缩和打包操作
一.写在前面 本节将对Linux的磁盘文件系统.文件的压缩打包等操作进行简要介绍. 二.完成目标 1.了解磁盘文件系统的接本知识 2.操作文件和目录的相关命令 3.文件系统的简单操作命令 4.Lin ...
- ios百度地图不能定位问题
在IOS8中定位功能新增了两个方法: - (void)requestWhenInUseAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE ...