-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathp149.c
69 lines (69 loc) · 1.86 KB
/
p149.c
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
/**
* Definition for a point.
* struct Point {
* int x;
* int y;
* }
*/
int maxPoints(struct Point* points, int pointsSize) {
if (pointsSize <= 1) return pointsSize;
int i, j, k;
int result = 0;
int tmp = 0;
long long x1, x2, y1, y2;
bool *noteqlmem = (bool*)malloc(sizeof(bool)*pointsSize);
bool *eqlmem = (bool*)malloc(sizeof(bool)*pointsSize);
for (i = 0; i < pointsSize; i++)
{
eqlmem[i] = false;
}
for (i = 0; i < pointsSize; i++)
{
for (k = 0; k < pointsSize; k++)
{
noteqlmem[k] = false;
}
for (j = i+1; j < pointsSize; j++)
{
if (points[i].x != points[j].x || points[i].y != points[j].y)
{
if (noteqlmem[j]) continue;
tmp = 0;
x1 = points[i].x-points[j].x;
y1 = points[i].y-points[j].y;
for (k = 0; k < pointsSize; k++)
{
x2 = points[k].x-points[i].x;
y2 = points[k].y-points[i].y;
if (x1*y2 == x2*y1)
{
noteqlmem[k] = true;
tmp++;
}
}
if (tmp > result)
{
result = tmp;
}
}
else
{
if (eqlmem[j]) continue;
tmp = 0;
for (k = 0; k < pointsSize; k++)
{
if (points[i].x == points[k].x && points[i].y == points[k].y)
{
eqlmem[k] = true;
tmp++;
}
}
if (tmp > result)
{
result = tmp;
}
}
}
}
return result;
}