5 struct line
{ enum {horz
, vert
} d
; int x1
; int y1
; int x2
; int y2
; };
7 #define max(x, y) ((x)>(y) ? (x) : (y))
8 #define min(x, y) ((x)<(y) ? (x) : (y))
9 #define between(a, a1, a2) ((a) >= min(a1, a2) && (a) <= max(a1, a2))
11 int parse_lines(struct line lines
[], int *maxx
, int *maxy
)
15 while (fgets(buf
, 1000, stdin
) != NULL
) {
17 lines
[i
].x1
= strtol(p
, &p
, 10);
19 lines
[i
].y1
= strtol(p
, &p
, 10);
21 lines
[i
].x2
= strtol(p
, &p
, 10);
23 lines
[i
].y2
= strtol(p
, &p
, 10);
24 if (lines
[i
].x1
== lines
[i
].x2
)
26 else if (lines
[i
].y1
== lines
[i
].y2
)
30 *maxx
= max(*maxx
, lines
[i
].x1
);
31 *maxx
= max(*maxx
, lines
[i
].x2
);
32 *maxy
= max(*maxy
, lines
[i
].y1
);
33 *maxy
= max(*maxy
, lines
[i
].y2
);
39 bool online(int x
, int y
, struct line line
)
43 return x
== line
.x1
&& between(y
, line
.y1
, line
.y2
);
45 return y
== line
.y1
&& between(x
, line
.x1
, line
.x2
);
52 struct line lines
[1000];
53 int maxx
= 0, maxy
= 0;
54 int nlines
= parse_lines(lines
, &maxx
, &maxy
);
56 for (int x
= 0; x
<=maxx
; x
++) {
57 for (int y
= 0; y
<=maxy
; y
++) {
59 for (int line
= 0; line
<nlines
&& matches
< 2; line
++)
60 if (online(x
, y
, lines
[line
]))
62 r
= matches
>= 2 ? r
+1 : r
;