Solução do Problema Point Location Test do CSES
Resolução problema Point Location Test do CSES.
Solução do Problema Point Location Test do CSES
Problem
There is a line that goes through the points \(p_1=(x_1,y_1)\) and \(p_2=(x_2,y_2)\). There is also a point \(p_3=(x_3,y_3)\). Your task is to determine whether \(p_3\) is located on the left or right side of the line or if it touches the line when we are looking from \(p_1 to p_2\).
Input
The first input line has an integer \(t\): the number of tests. After this, there are \(t\) lines that describe the tests. Each line has six integers: \(x_1, y_1, x_2, y_2, x_3 and y_3\).
Output
For each test, print “LEFT”, “RIGHT” or “TOUCH”.
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
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Ponto
{
int x;
int y;
};
int left(Ponto p, Ponto q, Ponto r)
{
return ( (q.x - p.x) * (r.y - p.y) - (r.x - p.x) * (q.y - p.y) > 0 );
}
int colinear(Ponto p, Ponto q, Ponto r)
{
return ( (q.x - p.x) * (r.y - p.y) - (r.x - p.x) * (q.y - p.y) == 0 );
}
void solve()
{
int x1,x2,x3,y1,y2,y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 ;
Ponto p = {x1,y1};
Ponto q = {x2,y2};
Ponto r = {x3,y3};
if(left(p,q,r))
cout << "LEFT" << endl;
else if(colinear(p, q, r))
cout << "TOUCH" << endl;
else
cout << "RIGHT" << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
This post is licensed under CC BY 4.0 by the author.