Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 유니티
- 정렬
- Team Fortress 2
- 백준
- 알고리즘
- 수학
- 자료구조
- 구현
- Unreal Engine 5
- 백트래킹
- ue5
- 브루트포스
- 재귀
- 투 포인터
- 우선순위 큐
- 그리디 알고리즘
- 다익스트라
- XR Interaction Toolkit
- 스택
- 다이나믹 프로그래밍
- VR
- 유니온 파인드
- 시뮬레이션
- 문자열
- BFS
- c++
- 트리
- 누적 합
- 그래프
- DFS
Archives
- Today
- Total
1일1알
백준 1986번 체스 C++ 본문
https://www.acmicpc.net/problem/1986
1986번: 체스
첫째 줄에는 체스 판의 크기 n과 m이 주어진다. (1 ≤ n, m ≤ 1000) 그리고 둘째 줄에는 Queen의 개수와 그 개수만큼의 Queen의 위치가 입력된다. 그리고 마찬가지로 셋째 줄에는 Knight의 개수와 위치,
www.acmicpc.net
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int dRow_Q[8] = { -1,1,1,-1,-1,0,1,0 };
int dCol_Q[8] = { 1,1,-1,-1,0,1,0,-1 };
int dRow_K[8] = { -2,-1,1,2,2,1,-1,-2 };
int dCol_K[8] = { 1,2,2,1,-1,-2,-2,-1 };
int n, m, q, k, p;
vector<vector<int>> board;
vector<pair<int, int>> queens;
vector<pair<int, int>> knights;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
board = vector<vector<int>>(n + 1, vector<int>(m + 1, 0));
cin >> q;
for (int i = 0; i < q; i++) {
int r, c;
cin >> r >> c;
board[r][c] = 1;
queens.push_back({ r,c });
}
cin >> k;
for (int i = 0; i < k; i++) {
int r, c;
cin >> r >> c;
board[r][c] = 2;
knights.push_back({ r,c });
}
cin >> p;
for (int i = 0; i < p; i++) {
int r, c;
cin >> r >> c;
board[r][c] = 3;
}
for (auto a : queens) {
int row = a.first;
int col = a.second;
for (int i = 0; i < 8; i++) {
int nextRow = row;
int nextCol = col;
while (true) {
nextRow += dRow_Q[i];
nextCol += dCol_Q[i];
if (nextRow <= 0 || nextRow > n) break;
if (nextCol <= 0 || nextCol > m) break;
if (board[nextRow][nextCol] > 0) break;
board[nextRow][nextCol] = -1;
}
}
}
for (auto a : knights) {
int row = a.first;
int col = a.second;
for (int i = 0; i < 8; i++) {
int nextRow = row + dRow_K[i];
int nextCol = col + dCol_K[i];
if (nextRow <= 0 || nextRow > n) continue;
if (nextCol <= 0 || nextCol > m) continue;
if (board[nextRow][nextCol] > 0) continue;
board[nextRow][nextCol] = -1;
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (board[i][j] == 0) ans++;
}
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 19637번 IF문 좀 대신 써줘 C++ (1) | 2023.06.06 |
---|---|
백준 18404번 현명한 나이트 C++ (0) | 2023.06.04 |
백준 15664번 N과 M(10) C++ (0) | 2023.05.30 |
백준 20365번 블로그2 C++ (0) | 2023.05.29 |
백준 10972번 다음 순열 C++ (0) | 2023.05.28 |