about summary refs log tree commit diff
path: root/NTU/moco.c
blob: 9354a0f9822e45060833da48e7f5226bb204bc2a (plain) (blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>

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;
}