회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
60퍼에서 에러가 나요 ㅠㅠ
4963번 - 섬의 개수
aszd0708
2년 전
0
여러가지 반례도 맞고 다 맞는데 저는 이 코드한테 쳐맞고있네요 ㅠㅠㅠㅠㅠ
도와주세요 ㅠㅠㅠ
#include <iostream> #include <vector> #include <queue> #include <tuple> #define MAX 51 using namespace std; typedef struct { int X, Y; }Vector2; Vector2 dir[8] = { {-1, -1}, {0, -1}, {1, -1}, {-1, 0}, /* */{1, 0}, {-1, 1}, {0, 1}, {1, 1} }; int map[MAX][MAX]; bool isVisited[MAX][MAX]; vector<int> islands; int islandNum; void input(int& w, int& h); void printAll(); void visit(int& w, int& h); void islandCount(Vector2 pos, int& w, int& h); int main() { int w, h; // 지도의 가로, 세로 w = h = 0; do { input(w, h); visit(w, h); if ((w != 0) && (h != 0)) { islands.push_back(islandNum); islandNum = 0; } fill(&isVisited[0][0], &isVisited[w][h], false); } while ((w != 0) && (h != 0)); printAll(); return 0; } void input(int& w, int& h) { cin >> w >> h; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { cin >> map[y][x]; } } } void printAll() { for (int i = 0; i < islands.size(); i++) cout << islands[i] << "\n"; } void visit(int& w, int& h) { for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (isVisited[y][x] == true || map[y][x] != 1) continue; else { Vector2 pos = { x, y }; islandCount(pos, w, h); islandNum++; } } } } void islandCount(Vector2 pos, int& w, int& h) { queue<Vector2> q; q.push(pos); while (!q.empty()) { Vector2 curPos = q.front(); q.pop(); if (isVisited[curPos.Y][curPos.X] == true) continue; // 재방문 if (map[curPos.Y][curPos.X] == 0) continue; // 바다 isVisited[curPos.Y][curPos.X] = true; for (int i = 0; i < 8; i++) { Vector2 movePos = { curPos.X + dir[i].X, curPos.Y + dir[i].Y }; if (movePos.X < 0 || movePos.X >= w || movePos.Y < 0 || movePos.Y >= h) continue; // 범위 이탈 q.push(movePos); } } }
댓글을 작성하려면
로그인
해야 합니다.
aszd0708 2년 전
여러가지 반례도 맞고 다 맞는데 저는 이 코드한테 쳐맞고있네요 ㅠㅠㅠㅠㅠ
도와주세요 ㅠㅠㅠ