From 2a7bc10f6c011d19fb3b0e73068f7e1a9c30ace0 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Sat, 8 Oct 2016 09:56:43 +0700 Subject: Initial commit --- NTU/moco.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 NTU/moco.c (limited to 'NTU/moco.c') diff --git a/NTU/moco.c b/NTU/moco.c new file mode 100644 index 0000000..9354a0f --- /dev/null +++ b/NTU/moco.c @@ -0,0 +1,77 @@ +#include + +typedef struct { + short x; + short y; +} point_t; + +point_t a, b, c, d; + +long long cross_product(point_t m, point_t n, point_t p, point_t q) +{ + return (n.x - m.x) * (q.y - p.y) - (q.x - p.x) * (n.y - m.y); +} + +char convex() +{ + if (cross_product(a, c, c, b) * cross_product(a, c, c, d) > 0) + return 0; + if (cross_product(b, d, d, a) * cross_product(b, d, d, c) > 0) + return 0; + return 1; +} + +void swap(point_t *m, point_t *n) +{ + short tmp = m->x; + m->x = n->x; + n->x = tmp; + tmp = m->y; + m->y = n->y; + n->y = tmp; +} + +long long dot_product(point_t m, point_t n, point_t p, point_t q) +{ + return (n.x - m.x) * (q.x - p.x) + (n.y - m.y) * (q.y - p.y); +} + +char f2() +{ + return !dot_product(a, b, b, c); +} + +char f3() +{ + return !dot_product(a, c, b, d); +} + +char f4() +{ + return (a.x + c.x == b.x + d.x) && (a.y + c.y == b.y + d.y); +} + +int main() +{ + scanf("%hd %hd %hd %hd %hd %hd %hd %hd", + &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &d.x, &d.y); + + if (!convex()) { + swap(&a, &b); + if (!convex()) + swap(&b, &c); + } + + char val = 5; + if (f4()) { + val = 4; + if (f2()) + val = 2; + if (f3()) + val--; + } + + printf("%hhd\n", val); + + return 0; +} -- cgit 1.4.1