https://www.acmicpc.net/problem/10157
10157번: 자리배정
첫 줄에는 공연장의 격자 크기를 나타내는 정수 C와 R이 하나의 공백을 사이에 두고 차례대로 주어진다. 두 값의 범위는 5 ≤ C, R ≤ 1,000이다. 그 다음 줄에는 어떤 관객의 대기번호 K가 주어진다.
www.acmicpc.net
//[C++] 백준 문제풀이 (Bruteforcing)
#include <bits/stdc++.h>
int r, c, k;
int seats[1001][1001];
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> c >> r >> k;
if (k > r * c) {
std::cout << 0 << "\n";
return 0;
}
int y = 1, x = 1;
int number = 1;
seats[y][x] = number;
while(number <= k){
if (number == k){
std::cout << x << " " << y << "\n";
break;
}
while(y < r && number < k && seats[y + 1][x] == 0){
++y;
++number;
seats[y][x] = number;
}
while(x < c && number < k && seats[y][x + 1] == 0){
++x;
++number;
seats[y][x] = number;
}
while(y > 1 && number < k && seats[y - 1][x] == 0){
--y;
++number;
seats[y][x] = number;
}
while(x > 1 && number < k && seats[y][x - 1] == 0){
--x;
++number;
seats[y][x] = number;
}
}
return 0;
}
'백준 문제풀이 > Bruteforcing' 카테고리의 다른 글
[C++] 백준 문제풀이 (Bruteforcing) 2670번 연속부분최대곱 (0) | 2023.06.27 |
---|---|
[C++] 백준 문제풀이 (Bruteforcing) 2615번 오목 (0) | 2023.06.27 |
[C++] 백준 문제풀이 (Bruteforcing) 4375번 1 (0) | 2023.06.27 |
[C++] 백준 문제풀이 (Bruteforcing) 2210번 숫자판 점프 (0) | 2023.06.27 |
[C++] 백준 문제풀이 (Bruteforcing) 1145번 적어도 대부분의 배수 (0) | 2023.06.27 |