# 컨베이어 벨트

나만의 시뮬레이션 문제 풀이 전략!

긴 문제 설명에 압도당하지 말고, 말 그대로 시뮬레이션을 해보는 것이다!\
단, 문제를 정확하게 이해하고, 문제 조건을 정확하게 파악하고 구현하는 것이 중요하다!

2번째 틀린 이유 : Scanner랑 BufferedReader 섞어서 쓰지말자. IDE에서는 정상적으로 동작하지만, 코드를 채점 프로그램에 제출하면 정확한 원인은 모르겠으나 입력을 받는 과정에서 NoElment 에러발생.

틀린 이유

문제를 잘못이해함

* 로봇은 1번 칸에 올리고, N번 칸에서 내린다.\
  \&#xNAN;**=>로봇의 회전, 이동 범위 : 0 \~ N-1⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐**

문제 설명\
벨트가 회전할 때 N=>N+1이 되고, 2N은 1이 된다고 했다. 벨트의 회전 범위는 배열 인덱스로 따지자면 0\~(2N-1)이다.\
로봇 옮기는 과정의 첫번째 회전 단계에서 벨트는 로봇과 함께 회전한다고 했다.\
**이는 함께 회전할 뿐이지, 로봇은 N-1 위치에서 내려줘야한다!⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️**\
로봇도 벨트와 함께 0  2N-1 범위로 회전하는 것이 아니다‼️‼️‼️‼️‼️‼️‼️‼️‼️‼️‼️

틀린 이유

1. 회전\
   로봇 회전 : 로봇이 오른쪽으로 1칸 회전한 후 0번째는 로봇이 없는 걸로 처리해줘야한다!!!\
   **로봇은 0\~N-1 범위 내에서 회전하고, 회전단계에서는 회전만 한다!**\
   로봇 회전 범위가 0\~2N-1 로 생각하고, 0번ㄴ째 칸에 2N-1로봇이 이동하는 거라고 잘못 생각해서 틀렸다.
2. 로봇 이동\
   \- 로봇의 현재위치를 x라고 하면 robot\[x+1] = 2; 로 처리하려고 생각했는데\
   현재 로봇이 어느 위치에 있는지 알 수 없어서 구현을 생각해내지 못했다.\
   \=> **for문 돌리면서 i번째 칸에 로봇이 있다면 +1번째 칸으로 이동처리**해주면 된다.\
   \- **현재위치 => 다음위치 이동할 때 현재위치 로봇은 '0'으로 없는 것으로 처리**해줘야한다!
3. 로봇 올린다.

```java
package ss;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class RobotOnConveyerBelt {
	static int[] robot,conveyer;
	static int N,K;
	static void rotate_belt_robot() {
		int tmp = conveyer[2*N-1];
		int r_tmp = robot[2*N-1];
		for(int i=2*N-1;i>0;i--) {
			conveyer[i] = conveyer[i-1];
			robot[i] = robot[i-1];
		}
		conveyer[0] = tmp;
		robot[0] = r_tmp;
	}
	
	static int solve() {
		int ans = 0;
		int cnt = 0;
		boolean flag = true;
		while(flag) {
			
			//1.로봇과 함께 벨트 회전.
			rotate_belt_robot();
			//2.로봇 이동.
			int r_next = 0;//로봇현재위치 +1. 로봇 현재위치=?
			if(robot[r_next]!=2 && conveyer[r_next] >=1) {//로봇이있는 경우.
				robot[r_next] = 2;
				conveyer[r_next]--;
			}
			//3.올리는 위치 0 아니면 로봇 올린다.
			if(conveyer[0] != 0) {
				robot[0] = 2;
				conveyer[0]--;
			} else {
				rotate_belt_robot();
			}
			for(int i=0;i<2*N;i++) {
				conveyer[i] = 0;
				cnt++;
				if(cnt == K) {
					flag = false;
				}
			}
			ans++;
		}
		return ans;
	}
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner sc = new Scanner(System.in);
		String[] input = br.readLine().split(" ");
		N = Integer.parseInt(input[0]);
		K = Integer.parseInt(input[1]);

		robot = new int[2*N];
		conveyer = new int[2*N];
		
		for(int i=0;i<2*N;i++) {
			conveyer[i] = sc.nextInt();
		}
		System.out.println(solve());
		
		br.close();
	}

}
//		for(int i=0;i<2*N;i++) {//i=0,1,2,3,4,5
//			input = br.readLine().split(" ");
//			conveyer[i] = Integer.parseInt(input[i]);
//		}
//for(int i=0;i<2*N;i++) {
//	System.out.print(conveyer[i]+" ");
//}
//System.out.println();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heunnajo.gitbook.io/algorithms-problem-solving-skills/undefined-1/undefined-4.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
