UVa 476 - Points in Figures Rectangles

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

題目網址
中文網址

Solution

暴力一個一個矩形判斷即可。

Code

UVa 476UVa 476 - Points in Figures Rectangles
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#include<cstdio>
#define N 10
struct Rec
{
double x1, y1, x2, y2;
}rec[11];
int main()
{
int count = 1;
while (getchar()=='r')
{
scanf("%lf%lf%lf%lf", &rec[count].x1, &rec[count].y1, &rec[count].x2, &rec[count].y2);
count++;
getchar();
}

bool in;
int i = 0;
double x, y;
while (scanf("%lf%lf", &x, &y) && x != 9999.9&&y != 9999.9)
{
in = false;
i++;
for (int j = 1; j<count; j++)
if (x > rec[j].x1&&x < rec[j].x2&&y<rec[j].y1&&y > rec[j].y2)
{
printf("Point %d is contained in figure %d\n", i, j);
in = true;
}

if (!in)
printf("Point %d is not contained in any figure\n", i);
}
return 0;
}