Recent Posts
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 | 31 |
Tags
- python
- JanusGateway
- 깡돼후
- PersistenceContext
- 달인막창
- 코루틴 빌더
- mp4fpsmod
- 오블완
- JanusWebRTC
- k8s #kubernetes #쿠버네티스
- 티스토리챌린지
- kotlin
- VARCHAR (1)
- terminal
- 코루틴 컨텍스트
- table not found
- JanusWebRTCServer
- vfr video
- taint
- JanusWebRTCGateway
- Spring Batch
- Value too long for column
- 헥사고날아키텍처 #육각형아키텍처 #유스케이스
- 자원부족
- PytestPluginManager
- tolerated
- pytest
- 겨울 부산
- 개성국밥
- preemption #
Archives
너와 나의 스토리
[BOJ] 4920 테트리스 게임 본문
반응형
문제: www.acmicpc.net/problem/4920
문제 풀이:
위 순으로 각각 2, 2, 4, 4, 1가지 경우의 수가 있다.
각 경우를 vector에 넣어주고, 모든 위치에서 해당 블록들을 놓아 합을 계산했다.
소스 코드:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
vector<vector<P>> blocks;
int n,arr[101][101],caseSize,answer;
void init() {
vector<P> block;
// 1-1
for (int i = 0; i < 4; i++) {
block.push_back({ 0,i });
}
blocks.push_back(block);
block.clear();
//1-2
for (int i = 0; i < 4; i++) {
block.push_back({ i,0 });
}
blocks.push_back(block);
block.clear();
//2-1
block.push_back({ 0,0 });
block.push_back({ 0,1 });
block.push_back({ 1,1 });
block.push_back({ 1,2 });
blocks.push_back(block);
block.clear();
//2-2
block.push_back({ 0,0 });
block.push_back({ 1,-1 });
block.push_back({ 1,0 });
block.push_back({ 2,-1 });
blocks.push_back(block);
block.clear();
//3-1
block.push_back({ 0,0 });
for (int i = 0; i < 3; i++) {
block.push_back({ 1,-1+i });
}
blocks.push_back(block);
block.clear();
//3-2
block.push_back({ 0,0 });
for (int i = 0; i < 3; i++) {
block.push_back({ -1 + i,-1 });
}
blocks.push_back(block);
block.clear();
//3-3
block.push_back({ 0,0 });
for (int i = 0; i < 3; i++) {
block.push_back({ -1 ,-1+i });
}
blocks.push_back(block);
block.clear();
//3-4
block.push_back({ 0,0 });
for (int i = 0; i < 3; i++) {
block.push_back({ -1 + i,+1 });
}
blocks.push_back(block);
block.clear();
//4
block.push_back({ 0,0 });
block.push_back({ 1,0 });
block.push_back({ 0,1 });
block.push_back({ 1,1 });
blocks.push_back(block);
block.clear();
//5-1
block.push_back({ 0,0 });
for (int i = 0; i < 3; i++) {
block.push_back({ -1 ,-2+i });
}
blocks.push_back(block);
block.clear();
//5-2
block.push_back({ 0,0 });
for (int i = 0; i < 3; i++) {
block.push_back({-2+i,1 });
}
blocks.push_back(block);
block.clear();
//5-3
block.push_back({ 0,0 });
for (int i = 0; i < 3; i++) {
block.push_back({ 1,i });
}
blocks.push_back(block);
block.clear();
//5-4
block.push_back({ 0,0 });
for (int i = 0; i < 3; i++) {
block.push_back({ i,-1});
}
blocks.push_back(block);
block.clear();
}
int check(int curx,int cury,int blockNum) {
int sum=0;
for (int i = 0; i < 4; i++) {
int x = curx + blocks[blockNum][i].first;
int y = cury + blocks[blockNum][i].second;
if (x < 0 || x >= n || y < 0 || y >= n) return -100000000;
sum += arr[x][y];
}
return sum;
}
void func() {
answer = -100000000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < caseSize; k++) {
answer = max(answer, check(i, j, k));
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
init();
caseSize = blocks.size();
int testNum = 1;
while (1) {
cin >> n;
if (n == 0) return 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
}
}
func();
cout << testNum << ". " << answer<<'\n';
testNum++;
}
return 0;
}
반응형
'Algorithm > 브루트 포스 (Brute-Force )' 카테고리의 다른 글
[BOJ] 16955 오목, 이길 수 있을까? (0) | 2020.10.09 |
---|---|
[BOJ] 12100번 2048(Easy) (0) | 2020.06.01 |
[Programmers] 2019 카카오 개발자 겨울 인턴십 - 문자열 압축 (0) | 2020.05.04 |
[BOJ] 14889 스타트와 링크 (0) | 2020.03.30 |
(BOJ) 16235 나무 재테크 (0) | 2019.05.10 |
Comments