회원가입
로그인
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
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
질문게시판의 테스트케이스는 맞게 나오는것 같은데... 해결이 안돼요!
1012번 - 유기농 배추
jinyoung1105
6년 전
0
ㅠㅠ..... 1012 질문게시판에 올라온 테스트 케이스 돌려보면 맞는데...
놓친 부분이 무엇일까요?
미리 답변주신 분들께 감사드립니다 ㅠ.ㅠ!
package testss; import java.util.Scanner; //#include <iostream> //using namespace std; class Main { static int x, y, num; static int dx[] = { -1, 0, 1, 0 }; static int dy[] = { 0, -1, 0, 1 }; static int arr[][]; static boolean visit[][]; static int bfs(int yy, int xx) { visit[yy][xx] = true; for (int i = 0; i < 4; i++) { int a = yy + dy[i]; int b = xx + dx[i]; if (a >= 0 && a < y && b >= 0 && b < x) { if (arr[a][b] == 1 && visit[a][b] == false) { bfs(a, b); } } } return 0; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int testcase; testcase = sc.nextInt(); for (int q = 0; q < testcase; q++) { // cin>> x>>y>>num; x = sc.nextInt(); y = sc.nextInt(); num = sc.nextInt(); arr = new int[y][x]; visit = new boolean[y][x]; for (int t = 0; t < y; t++) { arr[t] = new int[x]; visit[t] = new boolean[x]; for (int k = 0; k < x; k++) { arr[t][k] = 0; visit[t][k] = false; } } int yt, xt; for (int j = 0; j < num; j++) { xt = sc.nextInt(); yt = sc.nextInt(); arr[yt][xt] = 1; } int count = 0; for (int i = 0; i < y; i++) { for (int j = 0; j < x; j++) { if (arr[i][j] == 1 && visit[i][j] == false) { bfs(i, j); count++; } } } System.out.println(count); } } }
댓글을 작성하려면
로그인
해야 합니다.
jinyoung1105 6년 전