• 카테고리

    질문 & 답변
  • 세부 분야

    알고리즘 · 자료구조

  • 해결 여부

    미해결

선생님, 제 코드에 질문이 있습니다.

21.01.19 15:38 작성 조회수 103

0

#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

queue<int> map;
vector<int> Q[10001];
int check[10001];
int PathCost[10001];
int count = 0;
int movement[3] = { 1,-1,5 };

int main() {
	int S, E;

	scanf("%d %d", &S, &E);
	
	
	
	
	check[S] = 1; //중복 계산을 피하기 위해. 방문 표시를 해준다. 
	PathCost[S] = 0;
	map.push(S);

	while (!map.empty()) {
		int current = map.front(); //현재 5이다. 
		//current와 연결되어 있는 것들을 모두 찾아준다.
		map.pop();
		for (int i = 0; i < 3; i++) {
			int result = current + movement[i];
			map.push(result);
			if (result == E) { printf("%d ", PathCost[result]);  }
			if (check[result] == 0) {
				check[result]=1;
				PathCost[result] = PathCost[current] + check[result];
				map.push(result);
			}
			else {
				continue;
			}
			
			
		}
	}


}

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!