회원가입
로그인
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
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
16928 자바 도저히 문제를 못찾겠습니다 ㅠ
16928번 - 뱀과 사다리 게임
kami1152
2년 전
0
이것저것 열심히 수정해 봤는데 도저히 통과가 안되네요 ㅠㅠ
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Main { static int[] field; static int[] fieldinfo; static boolean[] visted; static Queue<Integer> que = new LinkedList<>(); public static void main(String[] args) throws IOException { dfs d = new dfs(); } } class dfs { Queue<Integer> que = new LinkedList<>(); static node[] n = new node[101]; static int hash = 0; public dfs() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; for (int i = 1; i < 101; i++) { n[i] = new node(i, false); } st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(st.nextToken()); int M = Integer.parseInt(st.nextToken()); for (int i = 0; i < N; i++) { st = new StringTokenizer(br.readLine()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); n[x].setnode(y); } for (int i = 0; i < M; i++) { st = new StringTokenizer(br.readLine()); int u = Integer.parseInt(st.nextToken()); int v = Integer.parseInt(st.nextToken()); n[u].setnode(v); } que.offer(n[1].rocation); // 1 set n[1].check(); // node info <- true; while (!que.isEmpty()) { int p = que.poll(); // p = 1 // 2 3 4 5 6 7-99 //System.out.println(n[p].rocation + " " + n[p].gethash()); for (int i = 1; i < 7; i++) { int next = p + i; if (next > 100) { continue; } if (n[p + i].getvisited()) { continue; } if (n[p + i].getnextnode() == 0) { que.offer(n[p + i].rocation); n[p + i].hashinfoset(n[p].gethash()); n[p + i].check(); } if (n[p + i].getnextnode() != 0) { que.offer(n[p + i].getnextnode()); n[p + i].hashinfoset(n[p].gethash()); n[n[p + i].getnextnode()].hashinfoset(n[p].gethash()); n[p + i].check(); n[n[p + i].getnextnode()].check(); } if (n[p + i].rocation == 100) { break; } // System.out.println(n[p + i].rocation + "-" + n[p + i].gethash()); } } System.out.println(n[100].gethash()); } } class node { public int rocation; private boolean visted; private int hashinfo = 0; private int nextnode = 0; public node(int rocation, boolean visted) { this.rocation = rocation; this.visted = visted; } public void hashinfoset(int hash) { this.hashinfo = ++hash; } public int gethash() { return hashinfo; } public void setnode(int nextnode) { this.nextnode = nextnode; } public int getnextnode() { return nextnode; } public void check() { this.visted = true; } public boolean getvisited() { return visted; } }
댓글을 작성하려면
로그인
해야 합니다.
kami1152 2년 전
이것저것 열심히 수정해 봤는데 도저히 통과가 안되네요 ㅠㅠ