现在的位置: 首页 > 综合 > 正文

UVA10112

2014年08月29日 ⁄ 综合 ⁄ 共 2529字 ⁄ 字号 评论关闭

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 whathave been called power fields: a fairly small area, less than 100 meters squarewhere there are from four to fifteen tallmonuments with crystals
on top. Such an area is mapped out above. Most ofthe artifacts discovered have come frominside a triangular area between just three of the monuments, now calledthe power triangle. After considerableanalysis archeologists agree how this triangle is selected
from all thetriangles with three monuments as vertices: it isthe triangle with the largest possible area that does not contain any othermonuments inside the triangle or on an edgeof 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 thepower triangles in power fields. Write a program that takes the positions ofthe monuments in any number of powerfields 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) isthe 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 isthe number of monuments: at least 4, and at most 15. For each monumentthere is a data line that starts with a one character label for the monumentand is followedby the coordinates of
the monument, which are nonnegative integers less than100. 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 isindicated 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 threelabels of the vertices of the power triangle, listedin 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 
#include<stdio.h>
#include<math.h>
int fun(int x1,int y1,int x2,int y2,int x3,int y3)//计算有向面积并去绝对值
{
    return fabs(x1*y2+x2*y3+y1*x3-x3*y2-x2*y1-x1*y3);
}
int main()
{
    int i,j,k,z,T,o=0,p=0,q=0,x[16],y[16];
    char c[16][1];
    freopen("D:\\i.txt","r",stdin);
    while(scanf("%d",&T)!=EOF)
    {
        if(T==0)  break;
        int max=0,s;
        for(i=0;i<T;i++)
            scanf("%s%d%d\n",c[i],&x[i],&y[i]);
        for(i=0;i<T;i++)
        {
            for(j=i+1;j<T;j++)
            {
                for(k=j+1;k<T;k++)
                {
                    s=fun(x[i],y[i],x[j],y[j],x[k],y[k]);
                    if(s>max)
                    {
                        int flag=1;
                        for(z=0;z<T;z++)
                        {
                            if(z!=i&&z!=j&&z!=k)
                                if(s==fun(x[z],y[z],x[j],y[j],x[k],y[k])+fun(x[z],y[z],x[i],y[i],x[j],y[j])+fun(x[i],y[i],x[z],y[z],x[k],y[k]))//判断是否在三角形外面
                                {flag=0;break;}
                        }
                        if(flag)
                        {o=i;p=j;q=k;max=s;}
                    }
                }
            }
        }
        printf("%c%c%c\n",o+65,p+65,q+65);
    }
    return 0;
}

抱歉!评论已关闭.