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 |
Tags
- c++
- 브루트포스
- 투 포인터
- XR Interaction Toolkit
- 백준
- VR
- 다이나믹 프로그래밍
- 문자열
- 트리
- BFS
- 수학
- 유니온 파인드
- Team Fortress 2
- 시뮬레이션
- 유니티
- 그래프
- 알고리즘
- DFS
- 우선순위 큐
- 구현
- ue5
- Unreal Engine 5
- 그리디 알고리즘
- 정렬
- 백트래킹
- 스택
- 재귀
- 누적 합
- 다익스트라
- 자료구조
Archives
- Today
- Total
1일1알
백준 3019번 테트리스 C++ 본문
각 모양마다 모양의 맨 밑이 바닥과 얼마나 떨어져있는지를 모양의 정보로 저장해서 맵의 높이 - 모양의 맨 밑 값을 뺀 값이 모두 같으면 그 자리에 놓을 수 있다고 생각하는 식으로 문제를 해결하였다.
#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 <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int c, p;
vector<vector<string>> shapes(8, vector<string>());
vector<int> ans(8, 0);
void Init() {
shapes[1].push_back("0");
shapes[1].push_back("0000");
shapes[2].push_back("00");
shapes[3].push_back("001");
shapes[3].push_back("10");
shapes[4].push_back("100");
shapes[4].push_back("01");
shapes[5].push_back("000");
shapes[5].push_back("01");
shapes[5].push_back("101");
shapes[5].push_back("10");
shapes[6].push_back("000");
shapes[6].push_back("00");
shapes[6].push_back("011");
shapes[6].push_back("20");
shapes[7].push_back("000");
shapes[7].push_back("02");
shapes[7].push_back("110");
shapes[7].push_back("00");
}
void Solve(int idx, int shape, vector<int> &board) {
for (int i = 0; i < shapes[shape].size(); i++) {
int size = shapes[shape][i].length();
set<int> s;
int k = 0;
bool isAns = true;
for (int j = idx; j < idx + size; j++) {
if (j >= c) {
isAns = false;
break;
}
s.insert(board[j] - (shapes[shape][i][k] - '0'));
k++;
}
if (!isAns) continue;
if (s.size() == 1)ans[shape]++;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
Init();
cin >> c >> p;
vector<int> board(c);
for (int i = 0; i < c; i++) {
cin >> board[i];
}
for (int i = 0; i < c; i++) {
for (int j = 1; j <= 7; j++) {
Solve(i, j, board);
}
}
cout << ans[p];
};
'알고리즘' 카테고리의 다른 글
백준 5747 Odd or Even C++ (0) | 2022.01.23 |
---|---|
백준 2636번 치즈 C++ (0) | 2022.01.22 |
백준 16925번 문자열 추측 C++ (0) | 2022.01.20 |
백준 16958번 텔레포트 C++ (0) | 2022.01.19 |
백준 16945번 매직 스퀘어로 변경하기 C++ (0) | 2022.01.18 |