Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pi pair<int,int>
- #define x first
- #define y second
- using namespace std;
- ifstream fin("intersectiesegmente.in");
- ofstream fout("intersectiesegmente.out");
- int det(const pi &A, const pi &B, const pi &C) {
- return (B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y);
- }
- bool check(const pi &A, const pi &B, const pi &C) {
- vector<pi> a{A, B, C};
- int X = a[2].x, Y = a[2].y;
- sort(a.begin(), a.end());
- if(!(X == a[1].x && Y == a[1].y))
- return false;
- if(det(a[0], a[1], a[2]) == 0)
- return true;
- return false;
- }
- int main() {
- vector<pi> p(4);
- for(pi &x : p)
- fin >> x.x >> x.y;
- if(check(p[0], p[1], p[2])) {
- fout << "DA";
- return 0;
- }
- if(check(p[0], p[1], p[3])) {
- fout << "DA";
- return 0;
- }
- if(check(p[2], p[3], p[0])) {
- fout << "DA";
- return 0;
- }
- if(check(p[2], p[3], p[1])) {
- fout << "DA";
- return 0;
- }
- int d1 = det(p[0], p[1], p[2]),
- d2 = det(p[0], p[1], p[3]),
- d3 = det(p[2], p[3], p[0]),
- d4 = det(p[2], p[3], p[1]);
- if(d1 * d2 < 0 && d3 * d4 < 0)
- fout << "DA";
- else
- fout << "NU";
- }
Add Comment
Please, Sign In to add comment