본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 7782 : Alien

반응형

https://www.acmicpc.net/problem/7782

 

7782번: Alien

Once upon a time after winning another competition at KBTU, Bakhytzhan, Askar and Artem walked throw the Old Square. When they found some interesting rectangle lines on the asphalt, they stopped and screamed out ”R tree”. They screamed so loud that all

www.acmicpc.net

간단 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

외계인 함선 수 t, Bakhytzhan의 위치 (b1, b2), 함선의 좌하좌표 (lx, ly), 함선의 우상좌표 (rx, ry), 정답 ans를 선언 후 형식에 따라 입력받습니다.

📔 풀이과정

lx <= b1 <= rx, ly <= b2 <= ry라면 함선이 Bakhytzhan의 좌표에 착륙했을 조건이 됩니다. 착륙했었다면 ans = "Yes"로 바꿔줍니다.

📔 정답출력

ans를 출력합니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int t, b1, b2, lx, ly, hx, hy;
string ans = "No";
int main(){
  cin >> t >> b1 >> b2;
  while(t--){
    cin >> lx >> ly >> hx >> hy;
    if(lx <= b1 && b1 <= hx && ly <= b2 && b2 <= hy) ans = "Yes";
  }
  cout << ans;
}

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.