本文主要是介绍HDU5135 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): 1901 Accepted Submission(s): 1083
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.
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.
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
2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大)
Recommend
liuyiding | We have carefully selected several similar problems for you: 6022 6021 6020 6019 6018
有n个数,接下来有n个小木棍,要把它尽量围成多个三角形,并且使,围成的三角形的面积最大。
需要满足三个条件:
①三角形只能有三根棒组成
②三角形的顶点必须是棒的终点
③木棍不能用完
先按照贪心的思路给边排序,然后在枚举
代码:
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <set>
#include <iostream>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10000007
#define debug() puts("what the fuck!!!")
#define N 100
#define M 1000000
#define ll long long
using namespace std;
struct node
{double l;int vis;
} a[N];
int cmp(node a,node b)
{return a.l>b.l;
}
double mj(double a,double b,double c)
{double p=(a+b+c)/2;return sqrt(p*(p-a)*(p-b)*(p-c));
}
int jc(double a,double b,double c)
{if(a+b>c&&a+c>b&&b+c>a)return 1;elsereturn 0;
}
int main()
{int n;while(scanf("%d",&n)&&n){for(int i=1; i<=n; i++){scanf("%lf",&a[i].l);a[i].vis=0;}sort(a+1,a+n+1,cmp);double num=0.0;int flag;for(int i=1; i<=n; i++){flag=0;if(a[i].vis==0&&flag==0){for(int j=i+1; j<=n; j++){if(a[j].vis==0&&flag==0){for(int k=j+1; k<=n; k++){if(a[k].vis==0&&flag==0){if(jc(a[i].l,a[j].l,a[k].l)){//debug();num+=mj(a[i].l,a[j].l,a[k].l);a[i].vis=1;a[j].vis=1;a[k].vis=1;flag=1;break;}}}}}}}printf("%.2lf\n",num);}return 0;
}
这篇关于HDU5135 Little Zu Chongzhi's Triangles(计算几何,枚举)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!