-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangles_On_Surface.cs
More file actions
64 lines (64 loc) · 2.89 KB
/
Rectangles_On_Surface.cs
File metadata and controls
64 lines (64 loc) · 2.89 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
// напишите объявление структуры, которая бы описывала прямоугольник на плоскости (стороны параллельны осям).
// напишите функцию, которая получает одномерный массив прямоугольников и возвращает количество охватывающих прямоугольников для определенной точки на плоскост
namespace ConsoleApp45
{
class Program
{
public struct Rectangle
{
public double xUpLeft;
public double yUpLeft;
public double xDownRight;
public double yDownRight;
public Rectangle(double newxUpLeft, double newyUpLeft, double newxDownRight, double newyDownRight)
{
xUpLeft = newxUpLeft;
yUpLeft = newyUpLeft;
xDownRight = newxDownRight;
yDownRight = newyDownRight;
}
}
static void Main(string[] args)
{
Rectangle[] rectangles = new Rectangle[4];
rectangles[0] = new Rectangle(10, 10, 12, 5);
rectangles[1] = new Rectangle(-2, 4, 8, 2);
rectangles[2] = new Rectangle(6, 4, 11, 1);
Console.WriteLine("Количество пересечений: " + Search(rectangles));
}
public static void GetRec(Rectangle[] rectangles, Rectangle recResult, Rectangle recNew, int result, ref int max, int c)
{
if (!(recResult.yDownRight > recNew.yUpLeft || recResult.yUpLeft < recNew.yDownRight || recResult.xUpLeft > recNew.xDownRight || recResult.xDownRight < recNew.xUpLeft))
{
recResult.xUpLeft = Math.Max(recResult.xUpLeft, recNew.xUpLeft);
recResult.yUpLeft = Math.Min(recResult.yUpLeft, recNew.yUpLeft);
recResult.xDownRight = Math.Min(recResult.xDownRight, recNew.xDownRight);
recResult.yDownRight = Math.Max(recResult.yDownRight, recNew.yDownRight);
result++;
c++;
for (int k = c; k < rectangles.Length; k++)
{
GetRec(rectangles, recResult, rectangles[k], result, ref max, k);
}
if ((c == rectangles.Length) && (result > max)) max = result;
}
else
{
if (result > max) max = result;
}
}
public static int Search(Rectangle[] rectangles)
{
int max = 0;
for (int j = 0; j < rectangles.Length; j++)
{
for (int i = j + 1; i < rectangles.Length; i++)
{
GetRec(rectangles, rectangles[j], rectangles[i], 1, ref max, i);
}
}
return max;
}
}
}