BOJ : https://www.acmicpc.net/problem/17386

BOJ : https://www.acmicpc.net/problem/17387

 

삼각형의 면적 + 벡터의 식을 나타내는 CCW 를 이용하여 문제를 해결하였다.

 

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
#include <iostream>
#include <algorithm>
using namespace std;
 
typedef pair<long longlong long> xy;
 
long long ccw(xy a, xy b, xy c) {
    long long ans = (b.first - a.first) * (c.second - a.second) - (b.second - a.second) * (c.first - a.first);
    if (ans < 0return -1;
    else if (ans > 0return 1;
    return 0;
}
 
long long check(xy a, xy b, xy c, xy d) {
    long long ans1 = ccw(a, b, c) * ccw(a, b, d);
    long long ans2 = ccw(c, d, a) * ccw(c, d, b);
    if (ans1 == 0 && ans2 == 0) {
        if (a > b) swap(a, b);
        if (c > d) swap(c, d);
        if (a <= d && b >= c) return 1;
        else return 0;
    }
    if (ans1 <= 0 && ans2 <= 0return 1;
    else return 0;
}
 
int main() {
    xy a, b, c, d;
    cin >> a.first >> a.second >> b.first >> b.second;
    cin >> c.first >> c.second >> d.first >> d.second;
 
    printf("%lld", check(a, b, c, d));
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

'algorithm > BOJ' 카테고리의 다른 글

BOJ 3055번 탈출  (0) 2020.02.04
BOJ 4888번 문시티 건설  (0) 2020.02.03
BOJ 12781번 PIZZA ALVOLOC  (0) 2020.02.02
BOJ 16991번 외판원 순회3  (0) 2020.02.02
BOJ 2098번 외판원 순회  (0) 2020.02.02

+ Recent posts