Little Zu Chongzhi's Triangles

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 2515    Accepted Submission(s): 1427

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
 
Source
 
Recommend
liuyiding
 
 
 
大佬的代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<queue>
using namespace std;
const int MAXN=1e5+;
const double eps=1e-;
const int mod=1e9+;
#define INF 0x7fffffff
#define ll long long
#define edl putchar('\n')
#define useit ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define mst(a) memset(a,0,sizeof(a))
#define mstn(a,n) memset(a,n,sizeof(a))
//struct num{int a,i;}a[MAX];
//bool cmp(const num &a,const num &b){return a.a>b.a;}
//double cross(point a,point b){return (a.x*b.y-a.y*b.x);}
//double dot(point a,point b){return (a.x*b.x+a.y*b.y);}
float ans,a[];
int b[],n;
float solve(float a,float b,float c)
{
float p=(a+b+c)/;
if(b>c)
swap(b,c);
if(a>b)
swap(a,b);
if(b>c)
swap(b,c);
if((b+a)<=c)
return 0.00;
else
return sqrt(p*(p-a)*(p-b)*(p-c));
} void dfs(int time,float are)
{
if(time==)
ans=max(ans,are);
else
{
FOR(i,,n)
{
if(b[i])continue;
else
FOR(j,i+,n)
{
if(j==i||b[j])continue;
else
FOR(k,j+,n)
{
if(k==i||k==j||b[k])continue;
else
{
b[i]=,b[j]=,b[k]=;
dfs(time-,are+solve(a[i],a[j],a[k]));
b[i]=,b[j]=,b[k]=;
}
}
}
}
}
} int main()
{
while(scanf("%d",&n)&&n)
{
ans=0.00;
FOR(i,,n)
scanf("%f",&a[i]),b[i]=;
dfs(n/,);
printf("%.2f\n",ans);
}
}

HDU 5135.Little Zu Chongzhi's Triangles-字符串 (2014ACM/ICPC亚洲区广州站-重现赛)的更多相关文章

  1. HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))

    周六周末组队训练赛. Dogs' Candies Time Limit: 30000/30000 MS (Java/Others)    Memory Limit: 512000/512000 K ( ...

  2. HDU 5131.Song Jiang's rank list (2014ACM/ICPC亚洲区广州站-重现赛)

    Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java ...

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

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

  4. hdu 5135 Little Zu Chongzhi's Triangles

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

  5. HDU 5112 A Curious Matt (2014ACM/ICPC亚洲区北京站-重现赛)

    A Curious Matt Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) ...

  6. Little Zu Chongzhi's Triangles

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

  7. hdu5135 Little Zu Chongzhi's Triangles

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

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

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

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

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

随机推荐

  1. ARM linux中断总结

    Linux异常处理体系结构 Linux异常体系之vector_stub宏解析 Linux异常体系之stubs_offset Linux中断体系结构 ARM系统调用

  2. Cyclic Nacklace HDU - 3746 (kmp)

    Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. 大数运算:HDU-1042-N!(附N!位数的计算)

    解题心得: 这里使用了10000进制.很明显,因为是n!所以单个最大的数是10000*10000,使用万进制. 可以借鉴高精度的加法,单个乘了之后在进位. 很坑的一点,0!=1,数学不好WA了三次,尴 ...

  4. 访问tomcat出现HTTP Status 500 - java.lang.IllegalStateException: No output folder

    问题:tomcat分为安装版和解压缩版,解压缩版如果解压到安装盘,在浏览器中访问http://localhost:8080,可能会出现500错误,错误提示如下:  localhost:8080 jav ...

  5. 16,Python网络爬虫之Scrapy框架(CrawlSpider)

    今日概要 CrawlSpider简介 CrawlSpider使用 基于CrawlSpider爬虫文件的创建 链接提取器 规则解析器 引入 提问:如果想要通过爬虫程序去爬取”糗百“全站数据新闻数据的话, ...

  6. OpenCV学习笔记(九) 重映射、仿射变换

    重映射 通过重映射来表达每个像素的位置  : 这里  是目标图像,  是源图像,  是作用于  的映射方法函数.想象一下我们有一个图像  , 我们想满足下面的条件作重映射:,图像会按照  轴方向发生翻 ...

  7. Python中str、list、numpy分片操作

    在Python里,像字符串(str).列表(list).元组(tupple)和这类序列类型都支持切片操作 对对象切片,s是一个字符串,可以通过类似数组索引的方式获取字符串中的字符,同时也可以用s[a: ...

  8. Neural Network

    逻辑回归用神经网络节点的方式表示 前面已经介绍过逻辑回归的模型,样本为(x,y) 其中y的值为1或0,假设x有2个特征,则对应关系如下图所示.  实际情况是需要求需要三个参数,因此输入层需要添加一个 ...

  9. IOS开发学习笔记008-预处理

    预处理 1.宏定义 2.条件编译 3.文件包含 注意: 1.所有预处理都是以#开头,并且结尾不用分号. 2.宏名一般用大写字母,以便与变量名区别开来,但用小写也没有语法错误 3.作用域也是从定义到代码 ...

  10. Robotium之Android控件定位实践和建议

    本人之前曾经撰文描述Appium和UIAutomator框架是如何定位Android界面上的控件的. UIAutomator定位Android控件的方法实践和建议Appium基于安卓的各种FindEl ...