(C++) 백준 20055 컨베이어 벨트 위의 로봇
문제 및 풀이
https://www.acmicpc.net/problem/20055
구현
문제 조건 그대로 구현하면 되는 문제 .... ㅇㅅㅇ
- 이동하는 거 어떻게 표현 ? index를 기준으로 현재 1번인 위치 설정한다. 시계방향으로 이동하므로 단계마다 Index는 1씩 감소한다.
- index<0 일 때 index=2*N-1
 - index>=2N 일 때 index%=(2N)
 
 
- 내리는 위치 N은 두번 확인해야 함 !!!
1) 컨베이너 벨트가 이동하기 전 N번째 위치 (이전 단계에서 N번째에 존재하고 있을 수 있음)
2) 컨베이너 벨트가 이동한 후 N번째 위치 
코드
#include <iostream>
#include <vector>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int N,K;
    cin>>N>>K;
    vector<int> belt(N*2+1, 0);
    vector<bool> isRobot(N*2+1, false);
    for(int i=0; i<N*2; i++) cin>>belt[i];
    int pos=0;
    int level=0;
    while(true){
        level++;
        isRobot[(pos+(N-1))%(N*2)]=false; /// **************
        pos--;
        if(pos<0) pos=2*N-1;
        isRobot[(pos+(N-1))%(N*2)]=false;
        for(int i=N-2; i>0; i--){
            int tmp = (pos+i)%(N*2);
            if(!isRobot[tmp]) continue;
            int next = (tmp+1)%(N*2);
            if(belt[next]>0 && !isRobot[next]){
                isRobot[tmp]=false;
                isRobot[next]=true;
                belt[next]--;
            }
        }
        if(belt[pos]>0) {
            belt[pos]--;
            isRobot[pos]=true;
        }
        int cnt=0;
        for(int i=0; i<2*N; i++) {
           // cout<<belt[i]<<" ";
            if(belt[i]<=0) cnt++;
        }
        if(cnt>=K) break;
    }
    cout<<level;
}
                Author And Source
이 문제에 관하여((C++) 백준 20055 컨베이어 벨트 위의 로봇), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@minayeah/C-백준-20055-컨베이어-벨트-위의-로봇저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)