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 K (Java/Others)
Total Submission(s): 2515 Accepted Submission(s): 1427
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.
1 1 20
7
3 4 5 3 4 5 90
0
13.64
#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亚洲区广州站-重现赛)的更多相关文章
- HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))
周六周末组队训练赛. Dogs' Candies Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K ( ...
- 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 ...
- [HDU 5135] Little Zu Chongzhi's Triangles (dfs暴搜)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5135 题目大意:给你n条边,选出若干条边,组成若干个三角形,使得面积和最大.输出最大的面积和. 先将边 ...
- hdu 5135 Little Zu Chongzhi's Triangles
http://acm.hdu.edu.cn/showproblem.php?pid=5135 题意:给你N个木棍的长度,然后让你组成三角形,问你组成的三角形的和最大是多少? 思路:先求出可以组成的所有 ...
- HDU 5112 A Curious Matt (2014ACM/ICPC亚洲区北京站-重现赛)
A Curious Matt Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) ...
- Little Zu Chongzhi's Triangles
Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 ...
- hdu5135 Little Zu Chongzhi's Triangles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Total Submissi ...
- UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- UVALive 7077 Little Zu Chongzhi's Triangles (有序序列和三角形的关系)
这个题--我上来就给读错了,我以为最后是一个三角形,一条边可以由多个小棒组成,所以想到了状态压缩各种各样的东西,最后成功了--结果发现样例过不了,三条黑线就在我的脑袋上挂着,改正了以后我发现N非常小, ...
随机推荐
- A1095 Cars on Campus (30)(30 分)
A1095 Cars on Campus (30)(30 分) Zhejiang University has 6 campuses and a lot of gates. From each gat ...
- BZOJ - 2744 朋友圈 (二分图上的最大团)
[题目大意] 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着.一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他人的尊敬,所以现在就是需要你求朋友圈的最大数目.两 ...
- HDU:2846-Repository
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2846 Repository Time Limit: 2000/1000 MS (Java/Others) ...
- LCS及方案数(DP)
Description 对于一个序列
- 问题 1936: [蓝桥杯][算法提高VIP]最大乘积
问题 1936: [蓝桥杯][算法提高VIP]最大乘积 时间限制: 1Sec 内存限制: 128MB 提交: 77 解决: 16 题目描述 对于n个数,从中取出m个数,如何取使得这m个数的乘积最大呢? ...
- (PowerDesigner&Sqlite)PD中设计完表后,将其导入数据库中
本人连接过SQLServer跟SQLite Ⅰ.SQLServer,百度,转一下:http://jingyan.baidu.com/article/7f766daf465e9c4101e1d0d5.h ...
- Django--源码安装
1.安装setuptools cd /usr/src tar zxf setuptools-18.3.2.tar.gz cd setuptools-18.3.2/ python setup.py bu ...
- Android TV 开发(2)
本文来自网易云社区 作者:孙有军 首先来看看拨号界面的配置代码: <LinearLayout xmlns:android="http://schemas.android.com/apk ...
- 相当牛X的java版星际游戏
分享一款牛人用java写的经典游戏,目录结构如下: 虽然只能算一个Demo,但是用到了很多Java基础技术和算法: Java2D,双缓冲,A星寻路,粒子系统,动画效果,处理图片,Swing ui ,U ...
- linux环境搭建系列之jdk安装
JDK是java软件开发包的简称,要想开发java程序就必须安装JDK.没有JDK的话,无法编译Java程序. 前提: linux centOS6.6 64位操作系统 ROOT账号 安装包的获取:官网 ...