-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path147.cpp
54 lines (48 loc) · 1.39 KB
/
147.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
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
const int MAX = 1111111;
int P1,Q1,P2,Q2,P3,Q3;
int n,u,d,ans = 0x7FFFFFFF/2;
int main()
{
freopen("test.in","r",stdin);
ios::sync_with_stdio(false);
cin >> n;
cin >> P1 >> Q1 >> P2 >> Q2 >> P3 >> Q3;
if (abs(P1-P2) < abs(Q1-Q2)) {
swap(P1,Q1);
swap(P2,Q2);
swap(P3,Q3);
}
if (P1 > P2) {
swap(P1,P2);
swap(Q1,Q2);
}
for (int i = P1; i <= P2; ++i) {
int dist = abs(i - P3);
int l = Q3 - dist;
int r = Q3 + dist;
int d = max(max(1,Q1-abs(i-P1)),max(1,Q2-abs(i-P2)));
int u = min(min(n,Q1+abs(i-P1)),min(n,Q2+abs(i-P2)));
cout << d << " " << u << " " << dist << endl;
if ((l >= d && l <= u) ||
(r >= d && r <= u) ||
(l <= d && r >= u && u >= d)) {
ans = min(ans,dist);
}
}
if (ans >= ((P2-P1)/2-1)) {
cout << "NO" << endl;
cout << P2-P1-1 << endl;
} else {
cout << "YES" << endl;
cout << ans << endl;
}
return 0;
}