ZOJ-3752-The Three Guys【暴力】

来源:互联网 发布:360.cn 域名价格 编辑:程序博客网 时间:2024/05/01 11:54

3752-The Three Guys


Recent days, a joke spread out among Chinese social networks. “If Yao Ming, Guo Jingming and He Jiong lying on the ground, can they form a triangle?”

Some netizens think that it is impossible to form a triangle since Yao Ming is a basketball giant, while Guo Jingming and He Jiong are artists with short statures.

But another group of netizens came out and claim: “Yes, they can!” Someone even has presented a sketch to prove their theory:
这里写图片描述
There are three guys in somewhere of the world. They have learned of this idea and want to try it out by themselves. Given you the height of the three guys, please find out the maximum area of triangle they can form. The height consists of two parts: the upper part of body Ui and the lower part of body Li.

Input

There are multiple test cases (about 3000). For each test case:

There are three lines. Each line consists of two integers Ui and Li (1 <= Ui, Li <= 150) indicates the height of two parts of the i-th guy.

Output

For each test case, output the maximum area of triangle they can form. Any solution with a relative or absolute error of at most 1e-9 will be accepted.

Sample Input

10 10
20 20
30 30
Sample Output

600.000000000000

题目链接:ZOJ-3752

题目大意:求三个人能组成的最大的三角形面积,人是可以折叠的

题目思路:设想三个人六个点围成一个圆,按要求选出三个点,如果可以组成三角形的话,就求他们的面积。

全排列这六个数字,判断是否符合条件,人不可拆分。即判断相邻那点是否为同一个人

for (int i = 1; i <= 6; i += 2){     if (abs(c[i] - c[i + 1]) != 1) flag = 1;  //判断相邻两个点,是否属于同一个人}

比赛的时候,调了很久优化,未知Bug好多,后来发现直接暴力就可以…晕

以下是代码:

////  ZOJ-3752-The Three Guys.cpp//  ZOJ////  Created by pro on 16/4/15.//  Copyright (c) 2016年 pro. All rights reserved.//#include <iostream>#include <cmath>#include <cstring>#include <string>#include <cstdio>#include <vector>#include <algorithm>#include<map>using namespace std;//double ans = 0;int sum = 0;double area(int a,int b,int c){    if (a < b+c && a > abs(b-c)){        double p = (a+b+c)/2.0;        return sqrt(p*(p-a)*(p-b)*(p-c));    }    return 0;}double solve(int b[]){    double ans = 0;    for (int i = 1; i <= 6; i++)    {        for (int j = i + 1; j <= 6; j++)        {            for (int k = j + 1; k <= 6; k++)            {                int aa = 0,bb = 0,cc = 0;                for (int p = i + 1; p <= j; p++) aa += b[p];                for (int q = j + 1; q <= k; q++) bb += b[q];                cc = sum - aa - bb;                double ret = area(aa,bb,cc);                if (ret > ans) ans = ret;            }        }    }    return ans;}int main(){    int a[10],b[10];    int c[10] = {0,1,2,3,4,5,6};    while(cin >> a[1])    {        sum = a[1];        for (int i = 2; i <= 6; i++) cin >> a[i],sum += a[i];        double ans = 0;        do{            int flag = 0;            for (int i = 1; i <= 6; i += 2)            {                if (abs(c[i] - c[i + 1]) != 1) flag = 1;  //判断相邻两个点,是否属于同一个人            }            if (flag) continue;            for (int i = 1; i <= 6; i++)            {                b[i] = a[c[i]];            }            double ret = solve(b);            if (ret > ans) ans = ret;        }while(next_permutation(c + 1, c + 7));        printf("%.12f\n",ans);    }    return 0;}
0 0
原创粉丝点击