Follows 477.c (Total 78 lines):
/* @JUDGE_ID:4461XX 477 C */
/* A */
#include<math.h>
#include<stdio.h>
struct rectangle{
double lux ; /* left up */
double luy ;
double rdx ; /* right down */
double rdy ;
}rec[10] ;
struct circle{
double cenx ; /* center of the circle */
double ceny ;
double rad ; /* radius of the circle */
}cir[10] ;
struct figure{
char ch ;
int where ;
}figure[10] ;
int tailrec=-1 , tailcir=-1 , tailfig=-1 ;
int IsInRec( double x , double y , int where )
{
if( rec[where].lux<x && x<rec[where].rdx &&
rec[where].luy>y && y>rec[where].rdy ) return 1 ;
else return 0 ;
}
int IsInCir( double x , double y , int where )
{
if( sqrt( pow( cir[where].cenx-x , 2 ) + pow( cir[where].ceny-y , 2 ) ) <
cir[where].rad ) return 1 ;
else return 0 ;
}
int try_figure( double x , double y , int j )
{
switch( figure[j].ch ){
case 'r' : if( IsInRec( x , y , figure[j].where ) ) return 1 ;
break ;
case 'c' : if( IsInCir( x , y , figure[j].where ) ) return 1 ;
break ;
}
return 0 ;
}
void main( void )
{
char ch ;
int input_end , i , j , yes ;
double x , y ;
/* freopen( "C:\\windows\\desktop\\478.in" , "r" , stdin ) ;
freopen( "C:\\windows\\desktop\\478.out" , "w" , stdout ) ;*/
for( input_end=0 ; ; ){ /* input && make_struct */
scanf( "%c" , &ch ) ;
figure[++tailfig].ch = ch ;
switch( ch ){
case 'r' : tailrec++ ;
scanf( "%lf %lf %lf %lf\n" , &rec[tailrec].lux , &rec[tailrec].luy , &rec[tailrec].rdx , &rec[tailrec].rdy ) ;
figure[tailfig].where = tailrec ;
break ;
case 'c' : tailcir++ ;
scanf( "%lf %lf %lf\n" , &cir[tailcir].cenx , &cir[tailcir].ceny , &cir[tailcir].rad ) ;
figure[tailfig].where = tailcir ;
break ;
case '*' : input_end = 1 ;
break ;
}
if( input_end ) break ;
}
for( i=1 ; ; i++ ){
scanf( "%lf %lf" , &x , &y ) ;
if( x==9999.9 && y==9999.9 ) break ;
for( yes=j=0 ; j<tailfig ; j++ )
if( try_figure( x , y , j ) ){
yes = 1 ;
printf( "Point %d is contained in figure %d\n" , i , j+1 ) ;
}
if( !yes ) printf( "Point %d is not contained in any figure\n" , i ) ;
}
}
/* @END_OF_SOURCE_CODE */
Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com