题目链接:http://acm.jlu.edu.cn/joj/showproblem.php?pid=1259
-
#include <stdio.h>
-
#include <math.h>
-
-
struct Point
-
{
-
double x;
-
double y;
-
};
-
-
struct Figure
-
{
-
char type;
-
Point p1;
-
Point p2;
-
double r;
-
};
-
-
Figure fig [ 11 ];
-
Point pt [ 100 ];
-
-
-
bool In ( const Point& p, const Figure& f )
-
{
-
if (f. type == 'r' )
-
{
-
if (p. x > f. p1. x && p. x < f. p2. x && p. y > f. p2. y && p. y < f. p1. y )
-
return true;
-
return false;
-
}
-
else
-
{
-
if ( sqrt ( (p. x -f. p1. x ) * (p. x -f. p1. x ) + (p. y - f. p1. y ) * (p. y - f. p1. y ) ) < f. r )
-
return true;
-
return false;
-
}
-
}
-
-
int main ( int argc, char* argv [ ] )
-
{
-
int f_count,p_count;
-
f_count = 0;
-
while ( true )
-
{
-
if ( scanf ( "%c",&fig [f_count ]. type ) == EOF )
-
return 0;
-
else if (fig [f_count ]. type == '*' )
-
break;
-
else if (fig [f_count ]. type == 'r' )
-
scanf ( "%lf%lf%lf%lf",&fig [f_count ]. p1. x,&fig [f_count ]. p1. y,
-
&fig [f_count ]. p2. x,&fig [f_count ]. p2. y );
-
else
-
scanf ( "%lf%lf%lf",&fig [f_count ]. p1. x,&fig [f_count ]. p1. y,&fig [f_count ]. r );
-
getchar ( );
-
f_count++;
-
}
-
-
p_count = 0;
-
while ( true )
-
{
-
if ( scanf ( "%lf%lf",&pt [p_count ]. x,&pt [p_count ]. y ) == EOF )
-
return 0;
-
else if ( fabs (pt [p_count ]. x - 9999.9 ) < 1e -6 && fabs (pt [p_count ]. y - 9999.9 ) < 1e -6 )
-
break;
-
p_count++;
-
}
-
-
int i,j;
-
bool in;
-
for (i = 0;i < p_count;i++ )
-
{
-
in = false;
-
for (j = 0;j < f_count;j++ )
-
if (In (pt [i ],fig [j ] ) )
-
{
-
printf ( "Point %d is contained in figure %d/n",i + 1,j + 1 );
-
in = true;
-
}
-
if (!in )
-
printf ( "Point %d is not contained in any figure/n",i + 1 );
-
}
-
return 0;
-
}