f8dd1411502497e477237a2147037744a41be1e0
4 #define SWAP(x, y) { x ^= y; y ^= x; x ^= y; }
6 struct point
{ int x
; int y
; };
7 struct entry
{ struct point key
; int i
; UT_hash_handle hh
; };
9 void mark_point(int x
, int y
, struct entry
**entries
, int *r
)
12 struct point s
= {.x
=x
, .y
=y
};
13 HASH_FIND(hh
, *entries
, &s
, sizeof(struct point
), p
);
18 p
= malloc(sizeof(struct entry
));
21 HASH_ADD(hh
, *entries
, key
, sizeof(struct point
), p
);
28 struct entry
*entries
= NULL
;
30 while (fgets(buf
, 1000, stdin
) != NULL
) {
32 int x1
= strtol(ptr
, &ptr
, 10);
34 int y1
= strtol(ptr
, &ptr
, 10);
36 int x2
= strtol(ptr
, &ptr
, 10);
38 int y2
= strtol(ptr
, &ptr
, 10);
41 if (abs(y2
-y1
) == abs(x2
-x1
)) {
42 int dx
= x1
> x2
? -1 : 1;
43 int dy
= y1
> y2
? -1 : 1;
44 for (; x1
!= x2
; x1
+= dx
, y1
+= dy
)
45 mark_point(x1
, y1
, &entries
, &r
);
46 mark_point(x1
, y1
, &entries
, &r
);
54 for (int y
= y1
; y
<=y2
; y
++)
55 mark_point(x1
, y
, &entries
, &r
);
58 for (int x
= x1
; x
<=x2
; x
++)
59 mark_point(x
, y1
, &entries
, &r
);