fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 32549 (C++) Avoiding the Abyss
최초 업로드: 2025-11-08 23:00:20
최근 수정 시간: 2025-11-08 23:00:20
게시자: rlatjwls3333
카테고리: 백준
조회수: 6
# [Silver I] Avoiding the Abyss [문제 링크](https://www.acmicpc.net/problem/32549) ## 문제 설명 <p>You are standing on a point with integer coordinates $(x_s, y_s)$. You want to walk to the point with integer coordinates $(x_t, y_t)$. To do this, you can walk along a sequence of line segments. But there is a swimming pool in your way. The swimming pool is an axis aligned rectangle whose lower left corner is on the point $(x_l, y_l)$ and the upper right corner is on the point $(x_r, y_r)$. You cannot ever cross the swimming pool, not even on the border. However, it is dark and you do not know the coordinates $(x_l, y_l)$ and $(x_r, y_r)$. Instead, you threw a rock into the pool which revealed that the point $(x_p, y_p)$ is in the pool (or on the boundary).</p> <p>Find a way to walk from the start to the end point along a sequence of line segments, so that you never cross the swimming pool.</p> ## 입력 <p>The first line contains two integers $x_s$ and $y_s$ ($-10^4 \leq x_s, y_s \leq 10^4$).</p> <p>The second line contains two integers $x_t$ and $y_t$ ($-10^4 \leq x_t, y_t \leq 10^4$).</p> <p>The third line contains two integers $x_p$ and $y_p$ ($-10^4 \leq x_p, y_p \leq 10^4$).</p> <p>The problem is not adaptive, i.e. for every test case there exist four integers $x_l, y_l, x_r, y_r$ ($-10^4 \leq x_l < x_r \leq 10^4$, $-10^4 \leq y_l < y_r \leq 10^4$) that constitute a swimming pool. The start and end points are always strictly outside the swimming pool, and the point $(x_p,y_p)$ is inside (or on the border). The start and end points are always distinct.</p> ## 출력 <p>First, print one integer $N$ ($0 \leq N \leq 10$), the number of points in between the start and end point that you want to visit. Then, print $N$ lines, the $i$th containing two integers $x_i, y_i$. These coordinates must satisfy $-10^9 \leq x_i, y_i \leq 10^9$. Note that these are not the same bounds than on the other coordinates.</p> <p>This means that you will walk along straight line segments between $(x_s, y_s), (x_1, y_1), \dots, (x_N, y_N), (x_t, y_t)$ such that none of the line segments touch the swimming pool. It can be proven that a solution always exists.</p> ## 풀이 1. 웅덩이가 시작지점 오른쪽에 있으면 왼쪽으로 끝까지 가고, 아니면 오른쪽 끝까지 간다. 2. 웅덩이가 도착지점 위쪽에 있으면 아래쪽으로 돌아서 가고, 아니면 위쪽으로 돌아서 간다. ``` c++ #include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); int xs, ys, xe, ye, xp, yp; cin >> xs >> ys >> xe >> ye >> xp >> yp; cout << "3\n"; if(xs<xp) { cout << "-1000000000 " << ys << '\n'; if(ye>yp) cout << "-1000000000 1000000000\n" << xe << " 1000000000"; else cout << "-1000000000 -1000000000\n" << xe << " -1000000000"; } else { cout << "1000000000 " << ys << '\n'; if(ye>yp) cout << "1000000000 1000000000\n" << xe << " 1000000000"; else cout << "1000000000 -1000000000\n" << xe << " -1000000000"; } } ```