https://www.acmicpc.net/problem/2162
뻘짓을 굉장히 많이 했지만 생각보다 조건식이 간단했었다.
1. 선분이 무조건 안만난다 라는건 어떨때 그런가?
2. 선분이 평행했을때 조건은 어떻게 되나??
이 2개가 핵심이다.
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 | #include <iostream> #include <vector> #include <algorithm> #define ll long long int #define pii pair<ll , ll> using namespace std; int ccw(pii a, pii b, pii c) { ll d = a.first* b.second + b.first * c.second + c.first * a.second - a.second * b.first - b.second * c.first - c.second * a.first; if (d > 0) return 1; else if (d < 0) return -1; else return 0; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); pii p[4]; for (int i = 0; i < 4; i++) cin >> p[i].first >> p[i].second; int a = ccw(p[0], p[1], p[2]); int b = ccw(p[0], p[1], p[3]); int c = ccw(p[2], p[3], p[0]); int d = ccw(p[2], p[3], p[1]); if (a * b > 0 || c * d > 0) cout << 0; else if (a * b == 0 && c * d == 0) { if (p[0] > p[1]) swap(p[0], p[1]); if (p[2] > p[3]) swap(p[2], p[3]); if (p[0] <= p[2] && p[1] <= p[3]) cout << 1; else cout << 0; } else cout << 1; } | cs |
'뚝배기 터진 문제_boj' 카테고리의 다른 글
boj 4196 도미노 (0) | 2020.08.22 |
---|---|
boj3176 도로 네트워크 (0) | 2020.08.20 |
boj2618 경찰차 (0) | 2020.07.15 |
boj1086 박성원 (0) | 2020.07.03 |
boj 2098 외판원 순회 (0) | 2020.07.02 |