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
- 채팅서버 설계
- 전문가를 위한 스프링5
- 스프링
- 백준
- 팀300
- 스프링 핵심원리 기본편
- 스프링 시큐리티 구조
- SQL
- JPA
- 백준 1992번 풀이
- 객체지향의 사실과 오해
- 스프링 MVC 2편
- 스프링 입문을 위한 자바 객체 지향의 원리와 이해
- 백준 #N과 M(4) #백트래킹
- 가상 채팅서버
- 김영한님
- 자바의 정석 기초편
- 알고리즘
- 백준 2630번
- 타임리프
- 전문가를 위한 스프링
- 누구나큰일낼수있어
- 백준 1992번
- 1시간 만에 끝내는 직장인 코딩 용어
- thymeleaf
- 스파르타코딩클럽
- C++
- spartacodingclub
- 스프링심화반
- 스파르타코딩클럽 #spartacodingclub #누구나큰일낼수있어
Archives
- Today
- Total
민우의 코딩노트
백준 18808 - 스티커 붙이기 / C++ 본문
[문제]
https://www.acmicpc.net/problem/18808
[풀이]
시뮬레이션 + 회전 알고리즘
[코드]
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int note[42][42];
int r, c;
int paper[12][12];
// paper를 90도 회전하는 함수
void rotate(){
int tmp[12][12];
for(int i = 0; i < r; i++)
for(int j = 0; j < c; j++)
tmp[i][j] = paper[i][j];
for(int i = 0; i < c; i++)
for(int j = 0; j < r; j++)
paper[i][j] = tmp[r-1-j][i];
swap(r, c);
}
// note의 (x,y)에 모눈종이의 (0,0)이 올라가게 스티커를 붙일 수 있는지 판단하는 함수. 가능할 경우 note를 갱신한 후 true를 반환.
bool pastable(int x, int y){
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
if(note[x+i][y+j] == 1 && paper[i][j] == 1)
return false;
}
}
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
if(paper[i][j] == 1)
note[x+i][y+j] = 1;
}
}
return true;
}
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
while(k--){
cin >> r >> c;
for(int i = 0; i < r; i++)
for(int j = 0; j < c; j++)
cin >> paper[i][j];
for(int rot = 0; rot < 4; rot++){
bool is_paste = false; // 해당 스티커를 붙였는가?
for(int x = 0; x <= n-r; x++){
if(is_paste) break;
for(int y = 0; y <= m-c; y++){
if(pastable(x, y)){
is_paste = true;
break;
}
}
}
if(is_paste) break;
rotate();
}
}
int cnt = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cnt += note[i][j];
cout << cnt << '\n';
}
'Algorithm > BOJ' 카테고리의 다른 글
백준 15686 - 치킨 배달 / C++ (0) | 2022.01.23 |
---|---|
백준 - 12100번 2048 (Easy) / C++ (0) | 2022.01.23 |
백준 15683번 감시 - C++ (0) | 2022.01.22 |
백준 15652번 - N과 M (4) / C++ (0) | 2022.01.15 |
백준 15651번 - N과 M (3) - C++ (0) | 2022.01.13 |