-
Notifications
You must be signed in to change notification settings - Fork 313
/
secret_walls.c
60 lines (43 loc) · 1.21 KB
/
secret_walls.c
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
#include<stdio.h>
#include<math.h>
long long int x[1000000],y[1000000];
int main () {
long long int ans,l,h,pm,n,i,j,max,may,minx,miny;
scanf("%lld",&n);
pm=0;
max=0;
may=0;
for (i=0;i<n;i++)
{
scanf("%lld %lld",&x[i],&y[i]);
if (i==n-1)
{
pm = pm + (fabs(x[n-1]-x[0]) + fabs(y[n-1]-y[0])) ;
// l = fabs(x[n-1]-x[0]); h = fabs(y[n-1]-y[0]);
}
if (i==0)
continue;
pm = pm + (fabs(x[i]-x[i-1]) + fabs(y[i]-y[i-1]));
/* l = fabs(x[i]-x[i-1]); h = fabs(y[i]-y[i-1]);
if (l>max)
max=l;
if(h>may)
may=h;*/
}
minx=x[0];
miny=y[0];
for (i=0;i<n;i++)
{
if(x[i]>max)
max=x[i];
if(y[i]>may)
may=y[i];
if (x[i]<minx)
minx=x[i];
if (y[i]<miny)
miny=y[i];
}
ans = pm - 2*(max-minx+may-miny);
printf("%lld\n",ans);
return 0;
}