ACM (UVa) : 477


#include <stdio.h>
#include <math.h>

struct node {
    char c;
    double x1;
    double y1;
    double x2;
    double y2;
    double r;
} a [12];

bool call_circle (int index, double x, double y)
{
    double length = sqrt (pow (a [index].x1 - x, 2) + pow (a [index].y1 - y, 2));

    if ( length < a [index].r )
        return true;

    return false;
}


bool call_rectangle (int index, double x, double y)
{
    if ( a [index].x1 < x && a [index].y2 < y &&
    a [index].x2 > x && a [index].y1 > y )
        return true;

    return false;
}


int main ()
{
    char ch;
    int index = 0;

    while ( scanf ("%c", &ch) && ch != '*' ) {
        if ( ch != 'r' && ch != 'c' )
        continue;

        if ( ch == 'r' ) {
            a [index].c = ch;
            scanf ("%lf", &a [index].x1);
            scanf ("%lf", &a [index].y1);
            scanf ("%lf", &a [index].x2);
            scanf ("%lf", &a [index].y2);
        }

        if ( ch == 'c' ) {
            a [index].c = ch;
            scanf ("%lf", &a [index].x1);
            scanf ("%lf", &a [index].y1);
            scanf ("%lf", &a [index].r);
        }

        index++;
    }

    int numbering = 0;
    double x, y;
    while ( scanf ("%lf %lf", &x, &y) && x != 9999.9 && y != 9999.9 ) {

        bool flag = true;
        numbering++;
        for ( int i = 0; i < index; i++ ) {

            if ( a[i].c == 'r' ) {
                if ( call_rectangle (i, x, y) ) {
                    printf ("Point %d is contained in figure %d\n", numbering, i + 1 );
                    flag = false;
                }
            }

            else {
                if ( call_circle (i, x, y) ) {
                    printf ("Point %d is contained in figure %d\n", numbering, i + 1 );
                    flag = false;
                }
            }
        }

        if ( flag )
            printf ("Point %d is not contained in any figure\n", numbering);
    }

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s