zoukankan      html  css  js  c++  java
  • [解题报告]476 Points in Figures: Rectangles

     Points in Figures: Rectangles 

    Given a list of rectangles and a list of points in the x-y plane, determine for each point which figures (if any) contain the point.

    Input

    There will be ntex2html_wrap_inline220 ) rectangles descriptions, one per line. The first character will designate the type of figure (``r'' for rectangle). This character will be followed by four real values designating the x-ycoordinates of the upper left and lower right corners.

    The end of the list will be signalled by a line containing an asterisk in column one.

    The remaining lines will contain the x-y coordinates, one per line, of the points to be tested. The end of this list will be indicated by a point with coordinates 9999.9 9999.9; these values should not be included in the output.

    Points coinciding with a figure border are not considered inside.

    Output

    For each point to be tested, write a message of the form:

    Point i is contained in figure j

    for each figure that contains that point. If the point is not contained in any figure, write a message of the form:

    Point i is not contained in any figure

    Points and figures should be numbered in the order in which they appear in the input.

    Sample Input

    r 8.5 17.0 25.5 -8.5
    r 0.0 10.3 5.5 0.0
    r 2.5 12.5 12.5 2.5
    *
    2.0 2.0
    4.7 5.3
    6.9 11.2
    20.0 20.0
    17.6 3.2
    -5.2 -7.8
    9999.9 9999.9

    Sample Output

    Point 1 is contained in figure 2
    Point 2 is contained in figure 2
    Point 2 is contained in figure 3
    Point 3 is contained in figure 3
    Point 4 is not contained in any figure
    Point 5 is contained in figure 1
    Point 6 is not contained in any figure

    Diagrama of sample input figures and data points

    顺着题目要求做也没什么难的。。。。

    #include<stdio.h>
    int main()
    {
        double x_left[10], x_right[10], y_low[10], y_high[10];
        int i,rec=0,judge=0,counter=0;
        double a,b;
        char buf[100];
        char c;
        while(scanf("%c", &c)==1)
        {
            if(c=='*') break;
            if(c=='r')
            {
                scanf("%lf%lf%lf%lf", &x_left[rec], &y_high[rec], &x_right[rec], &y_low[rec]);
                rec++;
            }
        }
        while(scanf("%lf%lf",&a,&b)==2)
        {
            counter++;
            if(a==9999.9&&b==9999.9) break;
            judge=0;
            for(i=0;i<rec;i++)
            {
                if(x_left[i]<a && x_right[i]>a && y_low[i]<b && y_high[i]>b){
                   printf("Point %d is contained in figure %d\n", counter, i+1);
                   judge=1;
                }
            }
            if(judge==0)
                printf("Point %d is not contained in any figure\n", counter);
        }
        return 0;
    }
  • 相关阅读:
    BEGIN2 序列求和
    BEGIN2 序列求和
    《算法竞赛入门经典》 习题45 IP网络(IP Networks,ACM、ICPC NEERC 2005,UVa1590)
    C#中char空值的几种表示方式
    C#中char空值的几种表示方式
    C#中() =>是什么意思
    C#中() =>是什么意思
    C# Task 暂停与取消
    C# Task 暂停与取消
    C# WinForm设置透明
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2932187.html
Copyright © 2011-2022 走看看