-
Notifications
You must be signed in to change notification settings - Fork 0
/
1232.cpp
35 lines (32 loc) · 821 Bytes
/
1232.cpp
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
#include <bits/stdc++.h>
using namespace std;
bool checkStraightLine(vector<vector<int>> &coordinates)
{
// y2-y1/x2-x1
float m = float(coordinates[1][1] - coordinates[0][1]) / float(coordinates[1][0] - coordinates[0][0]);
int x1 = coordinates[0][0];
int y1 = coordinates[0][1];
for (auto i : coordinates)
{
if (i == coordinates[0])
{
continue;
}
float m1 = float(i[1] - y1) / float(i[0] - x1);
if ((m == INFINITY || m == -INFINITY )&& abs(m) == abs(m1))
{
continue;
}
if (m1 != m)
{
return false;
}
}
return true;
}
int main()
{
vector<vector<int>> v = {{0, 0}, {0, 5}, {5, 5}, {5, 0}};
cout << boolalpha << checkStraightLine(v) << endl;
cout << INFINITY;
}