509c555db0d13c35a5098f5ccddfd2a6a9b04cb0
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
)
13 memset(&s
, 0, sizeof s
);
16 HASH_FIND(hh
, *entries
, &s
, sizeof(struct point
), p
);
21 p
= calloc(1, sizeof(struct entry
));
24 HASH_ADD(hh
, *entries
, key
, sizeof(struct point
), p
);
31 struct entry
*entries
= NULL
;
33 while (fgets(buf
, 1000, stdin
) != NULL
) {
35 int x1
= strtol(ptr
, &ptr
, 10);
37 int y1
= strtol(ptr
, &ptr
, 10);
39 int x2
= strtol(ptr
, &ptr
, 10);
41 int y2
= strtol(ptr
, &ptr
, 10);
44 if (abs(y2
-y1
) == abs(x2
-x1
)) {
45 int dx
= x1
> x2
? -1 : 1;
46 int dy
= y1
> y2
? -1 : 1;
47 for (; x1
!= x2
; x1
+= dx
, y1
+= dy
)
48 mark_point(x1
, y1
, &entries
, &r
);
49 mark_point(x1
, y1
, &entries
, &r
);
57 for (int y
= y1
; y
<=y2
; y
++)
58 mark_point(x1
, y
, &entries
, &r
);
61 for (int x
= x1
; x
<=x2
; x
++)
62 mark_point(x
, y1
, &entries
, &r
);