ShovelingLife
A Game Programmer
ShovelingLife
전체 방문자
오늘
어제
  • 분류 전체보기 (1074)
    • 그래픽스 (57)
      • 공통 (19)
      • 수학 물리 (22)
      • OpenGL & Vulkan (1)
      • DirectX (14)
    • 게임엔진 (183)
      • Unreal (69)
      • Unity (103)
      • Cocos2D-X (3)
      • 개인 플젝 (8)
    • 코딩테스트 (221)
      • 공통 (7)
      • 프로그래머스 (22)
      • 백준 (162)
      • LeetCode (19)
      • HackerRank (2)
      • 코딩테스트 알고리즘 (8)
    • CS (235)
      • 공통 (21)
      • 네트워크 (44)
      • OS & 하드웨어 (55)
      • 자료구조 & 알고리즘 (98)
      • 디자인패턴 (6)
      • UML (4)
      • 데이터베이스 (7)
    • 프로그래밍 언어 (349)
      • C++ (168)
      • C# (90)
      • Java (9)
      • Python (33)
      • SQL (30)
      • JavaScript (8)
      • React (7)
    • 그 외 (10)
      • Math (5)
      • 일상 (5)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • Source Code 좌측 상단에 복사 버튼 추가 완료
  • 언리얼 엔진 C++ 빌드시간 단축 꿀팁
  • 게임 업계 코딩테스트 관련
  • 1인칭 시점으로 써내려가는 글들

인기 글

태그

  • C++
  • 유니티
  • string
  • 배열
  • 그래픽스
  • 언리얼
  • 프로그래머스
  • 오블완
  • 문자열
  • 함수
  • 클래스
  • 포인터
  • c#
  • 알고리즘
  • Unity
  • 티스토리챌린지
  • 백준
  • SQL
  • 파이썬
  • C

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ShovelingLife

A Game Programmer

코딩테스트/백준

[실1] 1926 - 그림

2022. 6. 19. 15:52
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <memory.h>
using namespace std;
 
#define MAX_SIZE 502
 
int board[MAX_SIZE][MAX_SIZE];
bool visited[MAX_SIZE][MAX_SIZE];
int n = 0, m = 0;
int dx[4]{ 1, 0, -1, 0 };
int dy[4]{ 0, 1, 0, -1 };
 
int main()
{
    cin >> n >> m;
 
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
            cin >> board[i][j];
    }
    int mx = 0; // 그림의 최대값
    int num = 0; // 그림의 수
 
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (board[i][j] == 0 ||
                visited[i][j])
                continue;
 
            num++;
            queue<pair<int, int>> q;
            visited[i][j] = true;
            q.push({ i,j });
            int area = 0;
 
            while (!q.empty())
            {
                area++;
                pair<int, int> cur = q.front();
                q.pop();
 
                for (int dir = 0; dir < 4; dir++)
                {
                    int nx = cur.first + dx[dir];
                    int ny = cur.second + dy[dir];
 
                    if (nx < 0 ||
                        nx >= n ||
                        ny < 0 ||
                        ny >= m)
                        continue;
 
                    if (visited[nx][ny] ||
                        !board[nx][ny])
                        continue;
 
                    visited[nx][ny] = true;
                    q.push({ nx,ny });
                }
            }
            mx = max(mx, area);
        }
    }
    cout << num << '\n' << mx;
    return 0;
}
저작자표시 (새창열림)

'코딩테스트 > 백준' 카테고리의 다른 글

[실1] 2667 - 단지 번호 붙이기  (0) 2022.06.19
[실2] 1406 - 에디터  (1) 2022.06.19
[실1] 2178 - 미로탐색  (0) 2022.06.19
[실2] 11724 - 연결 요소의 개수  (0) 2022.05.31
[실2] 1012 - 유기농 배추  (1) 2022.05.31
    '코딩테스트/백준' 카테고리의 다른 글
    • [실1] 2667 - 단지 번호 붙이기
    • [실2] 1406 - 에디터
    • [실1] 2178 - 미로탐색
    • [실2] 11724 - 연결 요소의 개수
    ShovelingLife
    ShovelingLife
    Main skill stack => Unity C# / Unreal C++ Studying Front / BackEnd, Java Python

    티스토리툴바