-
Notifications
You must be signed in to change notification settings - Fork 0
/
h016.cpp
86 lines (78 loc) · 1.81 KB
/
h016.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<iostream>
#include<fstream>
class DOR_D//distance of rectangle and dot
{
private:
int x1,y1;//dot1
int x2,y2;//dot2
int dot_x, dot_y;
public:
DOR_D(std::ifstream& put)
{
put>>x1;
put>>y1;
put>>x2;
put>>y2;
put>>dot_x;
put>>dot_y;
}
void distance()
{
int SLdistance =0;//직선(straight line)*****제곱
int RAdistance= 0;//직각(right angle)
if(dot_y<=y2 && dot_y>=y1 && dot_x<=x2 &&dot_x>=x1)//점이 사각형의 안쪽에 있을때
{
SLdistance = 0;
RAdistance = 0;
}
else if(dot_x<=x2 &&dot_x>=x1)//점이 사각형의 바로 위 혹은 아래에 있을때
{
RAdistance = abs(dot_y-y2) >abs(dot_y-y1) ? abs(dot_y-y1) : abs(dot_y-y2);
SLdistance = RAdistance*RAdistance;
}
else if(dot_y<=y2 && dot_y>=y1)//점이 사각형의 바로 옆에 있을때
{
RAdistance = abs(dot_x-x2) >abs(dot_x-x1) ? abs(dot_x-x1) : abs(dot_x-x2);
SLdistance = RAdistance*RAdistance;
}
else if(dot_x>x2)//점이 사각형의 오른쪽에 있을 때
{
if(dot_y>y2)//점이 사각형의 위에있을 때
{
SLdistance=(dot_x-x2)*(dot_x-x2) + (dot_y-y2)*(dot_y-y2);
RAdistance=dot_x-x2+dot_y-y2;
}
else if(dot_y<y1)//점이 사각형의 아래에 있을 때
{
SLdistance=(dot_x-x2)*(dot_x-x2) + (dot_y-y1)*(dot_y-y1);
RAdistance=dot_x-x2+y1-dot_y;
}
}
else if(dot_x<x1)//점이 사각형의 왼쪽에 있을때
{
if(dot_y>y2)//점이 사각형의 위에있을 때
{
SLdistance=(dot_x-x1)*(dot_x-x1) + (dot_y-y2)*(dot_y-y2);
RAdistance=x1-dot_x+dot_y-y2;
}
else if(dot_y<y1)//점이 사각형의 아레에 있을 때
{
SLdistance=(dot_x-x1)*(dot_x-x1) + (dot_y-y1)*(dot_y-y1);
RAdistance=x1-dot_x+y1-dot_y;
}
}
std :: cout<<SLdistance<<" " <<RAdistance<<std::endl;
}
};
void main()
{
std::ifstream put;
int cases;
put.open("input.txt");
put>>cases;
for(int i=0; i<cases; i++)
{
DOR_D distance(put);
distance.distance();
}
}