Competition/codeforces

Lyft Level 5 Challenge 2018 - Elimination Round A. King Escape

shyram 2019. 4. 9. 18:52

A. King Escape

https://codeforces.com/problemset/problem/1033/A


이게 dfs로 해도 되는데 귀찮아서 다른 방식으로 풀어봤다.

먼저 퀸을 기준으로 상단 좌측부터 하단 우측까지 영역을 총 4개로 나눌 수 있다.

킹과 목표 지점이 같은 영역에 속하면 이동 가능하다.

둘의 영역을 비교해보자.


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
#include <bits/stdc++.h>
using namespace std;
 
int n, a1, a2, b1, b2, c1, c2;
 
int area(int x, int y) {
    if (x < a1){
        if (y < a2) return 0;
        if (y > a2) return 1;
    }
    else {
        if (y < a2) return 2;
        if (y > a2) return 3;
    }
}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n >> a1 >> a2 >> b1 >> b2 >> c1 >> c2;
    int bb = area(b1, b2);
    int cc = area(c1, c2);
    if (cc == bb) {
        puts("YES\n");
        exit(0);
    }
    puts("NO\n");
    return 0;
}
cs