회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
스도쿠 틀렸다고 나오는데 한번 봐주세요!!!
2580번 - 스도쿠
lih2231
5년 전
0
안녕하세요! 지난번 범례를 꼭 찾아보라고 하셔서 이번엔 범례도 다 한번 보았습니다. 도움될만한 글이 없어 다시 이렇게 질문을 올립니다. 시험이 곧 코앞이라 마음이 급하내여;;; 흠 일단 테스트케이스는 맞았습니다. 그런데 틀리다고 나와서 sw expert사이트의 다른 테스트케이스로 테스트해보았는데 이상점없이 맞게 출력되었습니다. 어디가 틀렸는지 못찾겠어서 이렇게 질문올립니다. 도움 부탁드리겠습니다!!!!
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; public class Main { static int[][] map; static int rx, ry; static Queue<dot> que; static boolean check_b = false; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); que = new LinkedList<dot>(); rx = 0; ry = 0; map = new int[9][9]; for (int i = 0; i < 9; i=i+3) { for (int j = 0; j < 9; j=j+3) { que.add(new dot(i, j)); } } for (int i = 0; i < 9; i++) { String[] input = br.readLine().split(" "); for (int j = 0; j < 9; j++) { map[i][j] = Integer.parseInt(input[j]); } } int size = que.size(); for(int i = 0; i<size; i++) { dot dt = que.poll(); check_b = false; rx = dt.x; ry = dt.y; solve(dt.x, dt.y); } for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { System.out.print(map[i][j] + " "); }System.out.println(); } System.exit(0); } static void solve(int x, int y) { ArrayList<dot> al = new ArrayList<>(); ArrayList<Integer> d_al = new ArrayList<>(); int[] cut_map = new int[9]; int c = 0; for(int i = x; i < x+3; i++) { for(int j = y; j<y+3; j++) { cut_map[c] = map[i][j]; if(map[i][j] == 0) { al.add(new dot(i, j)); } c++; } } for(int a = 1; a<=9; a++) { boolean check = false; for(int b = 0; b<9; b++) { if(a == cut_map[b]) { check = true; } } if(check == false) { d_al.add(a); } } int[] arr = new int[al.size()]; for(int a = 0; a<d_al.size(); a++) { arr[a] = d_al.get(a); } dfs(0, al.size(), arr, al, d_al); } static void dfs(int pivot, int k, int[]arr, ArrayList<dot> al, ArrayList<Integer> d_al) { if(pivot == k) { if(check_F(al, arr)) { check_b = true; } return; } if(!check_b) { for(int i = pivot; i<d_al.size(); i++) { swap(pivot, i, arr); dfs(pivot+1, k, arr, al, d_al); swap(pivot, i, arr); } } } static boolean check_F(ArrayList<dot> al, int[] arr) { for(int i = 0; i<al.size(); i++) { map[al.get(i).x][al.get(i).y] = arr[i]; } int[] G_a = new int[9]; for(int i = rx; i<rx+3; i++) { for(int g = 0; g<9; g++) { G_a[g] = map[i][g]; } Arrays.sort(G_a); for(int j = 1; j<=9; j++) { int count = 0; for(int b = 0; b<9; b++) { if(j == G_a[b]) { count = count+1; } if(count > 1) { return false; } } } } int[] S_a = new int[9]; for(int i = ry; i<ry+3; i++) { for(int g = 0; g<9; g++) { S_a[g] = map[g][i]; } Arrays.sort(S_a); for(int j = 1; j<=9; j++) { int count = 0; for(int b = 0; b<9; b++) { if(j == S_a[b]) { count = count+1; } if(count > 1) { return false; } } } } return true; } static void swap(int i, int j, int[] arr) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } class dot { int x, y; dot(int x, int y){ this.x = x; this.y = y; } }
댓글을 작성하려면
로그인
해야 합니다.
lih2231 5년 전