POJ 1586 Three Sides Make a Triangle

Description

You work for an art store that has decided to carry every style and size of drafting triangle in existence. Unfortunately, sorting these has become a problem. The manager has given you the task of organizing them. You have decided to classify them by edge length and angles. To measure each triangle, you set it on a large sheet of very accurate graph paper and record the coordinate of each point. You then run these three points through a computer program to classify the triangles according to: 
Scalene no equal sides 
Isosceles two equal sides 
Equilateral three equal sides 
and 
Acute all angles under 90 
Right one angle equal 90 
Obtuse one angle over 90 
Of course, sometimes you make mistakes entering the data, so if you input points that do not form a valid triangle, your program should tell you.

Input

One triangle is described per line. Each line has six measurements taken to the nearest 0.001 in the order: 
x1 y1 x2 y2 x3 y3 
The final line of input will contain only a -1. 
None of the test sets contain non-right angles in the range 88-92 degrees, nor do any of the test sets include any non-equal side lengths for one triangle within 0.01 of one another.

Output

You will output one line for each triangle, which will contain two words: 
< length classification > < angle classification > 
or 
Not a Triangle 
The final line of your output file will be: 
End of Output

Sample Input

10.000 10.000 10.000 20.000 20.000 10.000
0.000 0.000 4.000 0.000 2.000 3.464
-1

Sample Output

Isosceles Right
Equilateral Acute
End of Output
题目水,但是精度真是蛋疼,WA了14发才试出来。
贴个代码,看看就好了。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
typedef long long LL;
typedef pairpil;
const int INF = 0x3f3f3f3f;
const int maxn=1e6+100;
const double eps1=0.001;
const double eps2=0.1;
double d[5][2];
double l1,l2,l3;
char str[1100];
double dis(int x,int y)
{
    return sqrt((d[x][0]-d[y][0])*(d[x][0]-d[y][0])+(d[x][1]-d[y][1])*(d[x][1]-d[y][1]));
}
int main()
{
    while(gets(str))
    {
        int cnt=0;int len=strlen(str);
        for(int i=0;i=eps2&&l1+l3-l2>=eps2&&l2+l3-l1>=eps2)
        {
            double x1=l1*l1+l2*l2-l3*l3;
            double x2=l1*l1+l3*l3-l2*l2;
            double x3=l2*l2+l3*l3-l1*l1;
            if(fabs(l1-l2)<=eps2&&fabs(l2-l3)<=eps2)
                printf("Equilateral Acute\n");
            else if(fabs(l1-l2)<=eps2||fabs(l2-l3)<=eps2||fabs(l1-l3)<=eps2)
            {
                printf("Isosceles ");
                if(fabs(x1-0.00)<=eps2||fabs(x2-0.00)<=eps2||fabs(x3-0.00)<=eps2)
                    puts("Right");
                else if(x1-eps1>0.00&&x2-eps1>0.00&&x3-eps1>0.00)
                    puts("Acute");
                else
                    puts("Obtuse");
            }
            else
            {
                printf("Scalene ");
                if(fabs(x1-0.00)<=eps2||fabs(x2-0.00)<=eps2||fabs(x3-0.00)<=eps2)
                    puts("Right");
                else if(x1-eps1>0.00&&x2-eps1>0.00&&x3-eps1>0.00)
                    puts("Acute");
                else
                    puts("Obtuse");
            }
        }
        else
            puts("Not a Triangle");
    }
    return 0;
}
/*
1 1 2 2 3 3
1 0 2 0 3 0
1 2 3 4 5 6
0 0 0 3 4 0
0 0 0 3 3 0
*/


你可能感兴趣的:(暴力)