UVa 10112 - Myacm Triangles

本文深入解析了Myacm文化中发现的神秘三角区域,这些区域由四到十五座高耸的带有水晶的纪念碑组成。通过数学公式计算,确定了每个区域内最大的不包含其他纪念碑的三角形——即所谓的‘权力三角’。本文详细介绍了如何通过输入纪念碑的位置坐标,利用程序自动化定位每个权力三角。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem B: Myacm Triangles

Source file:triangle.{c, cpp, java, pas}
Input file:triangle.in
Output file:triangle.out

There has been considerable archeological work on the ancient Myacm culture.  Many artifacts have been found in what have been called power fields:  a fairly small area, less than 100 meters square where there are from four to fifteen tall monuments with crystals on top.  Such an area is mapped out above.  Most of the artifacts discovered have come from inside a triangular area between just three of the monuments, now called the power triangle.  After considerable analysis archeologists agree how this triangle is selected from all the triangles with three monuments as vertices:  it is the triangle with the largest possible area that does not contain any other monuments inside the triangle or on an edge of the triangle.  Each field contains only one such triangle.

Archeological teams are continuing to find more power fields.  They would like to automate the task of locating the power triangles in power fields.  Write a program that takes the positions of the monuments in any number of power fields as input and determines the power triangle for each power field.

A useful formula:  the area of a triangle with vertices  (x1, y1), (x2, y2), and (x3, y3) is the absolute value of

0.5 × [(y3 - y1)(x2- x1) - (y2 - y1)(x3- x1)].

For each power field there are several lines of data.  The first line is the number of monuments: at least 4, and at most 15.  For each monument there is a data line that starts with a one character label for the monument and is followed by the coordinates of the monument, which are nonnegative integers less than 100. The first label is A, and the next is B, and so on.

There is at least one such power field described.  The end of input is indicated by a 0 for the number of monuments.  The first sample data below corresponds to the diagram in the problem.

For each power field there is one line of output.  It contains the three labels of the vertices of the power triangle, listed in increasing alphabetical order, with no spaces.

Example input:

6
A 1 0
B 4 0
C 0 3
D 1 3
E 4 4
F 0 6
4
A 0 0
B 1 0
C 99 0
D 99 99
0

Example output:

BEF
BCD
这道题目数据量不大,上限仅为15;穷举就行
#include <stdio.h>
#include <string.h>
#include <math.h>
struct num
{
    char c;
    double x,y;
}a[100];
int main()
{
    double cal(double x1,double y1,double x2,double y2,double x3,double y3);
    int i,j,n,m,t,x,y;
    double s,max,s1,s2,s3;
    char c1,c2,c3,c;
    while(scanf("%d%*c",&n)!=EOF)
    {
        if(n==0)
        {
            break;
        }
        for(i=1;i<=n;i++)
        {
            scanf("%c %lf %lf%*c",&a[i].c,&a[i].x,&a[i].y);
        }
        max=0;
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                for(x=1;x<=n;x++)
                {
                    if(i!=j&&i!=x&&j!=x)
                    {
                        s=cal(a[i].x,a[i].y,a[j].x,a[j].y,a[x].x,a[x].y);
                        for(y=1;y<=n;y++)
                        {
                            if(i!=y&&j!=y&&x!=y)
                            {
                                s1=cal(a[i].x,a[i].y,a[j].x,a[j].y,a[y].x,a[y].y);
                                s2=cal(a[i].x,a[i].y,a[y].x,a[y].y,a[x].x,a[x].y);
                                s3=cal(a[y].x,a[y].y,a[j].x,a[j].y,a[x].x,a[x].y);
                                if(fabs(s1+s2+s3-s)<=1e-7)
                                {
                                    break;
                                }
                            }
                        }
                        if(y==n+1&&s>max)
                        {
                            max=s;
                            c1=a[i].c; c2=a[j].c ;c3=a[x].c;
                        }
                    }
                }
            }
        }
        if(c1>c2)
        {
            c=c1; c1=c2; c2=c;
        }
        if(c1>c3)
        {
            c=c1; c1=c3 ;c3=c;
        }
        if(c2>c3)
        {
            c=c2 ; c2=c3 ; c3=c;
        }
        printf("%c%c%c\n",c1,c2,c3);
    }
    return 0;
}
double cal(double x1,double y1,double x2,double y2,double x3,double y3)
{
    double s;
    s=0.5 * ((y3 - y1)*(x2 - x1) - (y2 - y1)*(x3 - x1));
    return fabs(s);
}

 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值