본문 바로가기

Algorithm/Baekjoon_acmicpc

백준 1700 - 멀티탭스케줄링, 그리디,알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, search, greedy, baekjoon, bfs,dfs,acmicpc

 

// Process
// 1. Input countPlug, countMachine, useOrder
// 2. Iterate useOrder
//  2.1. If pug is not empty
//   2.1.1. 꽂혀있는 것들 중에서, 사용하는 물건인지 확인하고 그 중에 없으면
//                    뒤에 가장 근접하게 재사용하는 것들부터 남기고 가장 멀리있거나 다시 안쓰는 것을 뽑는다.
//   2.1.2. 뽑을 때 ++count
//  2.2. Plug new one
// 3. Return count

 

import java.io.*;
import java.util.*;

class MultitabSchedule {

    public static void main(String args[]) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // 1.
        String[] inputStrings = br.readLine().split(" ");
        int plugCount = Integer.parseInt(inputStrings[0]);
        int countMachine = Integer.parseInt(inputStrings[1]);

        int[] useOrder = new int[countMachine];
        StringTokenizer tokenizer = new StringTokenizer(br.readLine(), " ");
        for (int i = 0; i < useOrder.length; ++i) {
            useOrder[i] = Integer.parseInt(tokenizer.nextToken());
        }

        int count = 0;
        int[] plug = new int[plugCount];
        
        // 2.
        int[] distanceCounts;
        for (int i = 0; i < useOrder.length; ++i) {
            int emptyIndex = checkPlugEmptyIndex(plug);
            boolean isPluggedIn = checkAlreadyPluggedIn(plug, useOrder[i]);
            if (emptyIndex < 0 && !isPluggedIn) { // 빈자리가 없으면

                // 2.1.
                distanceCounts = new int[plug.length];
                for (int m = 0; m < plug.length; ++m) {
                    int distCount = 0;
                    boolean isFound = false;
                    for (int n = i + 1; !isFound && n < useOrder.length; ++n) {
                        ++distCount;
                        if (useOrder[n] == plug[m]) {
                            isFound = true;
                        }
                    }
                    if (isFound) {
                        distanceCounts[m] = distCount;
                    } else {
                        distanceCounts[m] = Integer.MAX_VALUE;
                    }
                }
                int maxIndex = -1;
                int maxDistance = -1;
                for (int m = 0; m < distanceCounts.length; ++m) {
                    if (distanceCounts[m] > maxDistance) {
                        maxDistance = distanceCounts[m];
                        maxIndex = m;
                    }
                }

                emptyIndex = maxIndex;

                // 2.1.1.
                ++count;
            }

            if (!isPluggedIn) {
                plug[emptyIndex] = useOrder[i];
            }
            
        }

        System.out.println(count);

        br.close();
    }
    
    public static int checkPlugEmptyIndex(int[] plug) {
        for (int i = 0; i < plug.length; ++i) {
            if (plug[i] == 0) {
                return i;
            }
        }
        return -1;
    }

    public static boolean checkAlreadyPluggedIn(int[] plug, int number) {
        for (int i = 0; i < plug.length; ++i) {
            if (number == plug[i]) {
                return true;
            }
        }
        return false;
    }
}

 

2021.04.28 - [Algorithm/Baekjoon_acmicpc] - 백준 11724 - 연결요소의개수, 너비우선, 깊이우선, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정, Leetcode, 릿코드, 코딩테스트, Tech interview, search, greedy, baekjoo..

 

백준 11724 - 연결요소의개수, 너비우선, 깊이우선, 프로그래머스, 알고리즘, Programmers, Stack, Queue, H

 금방 풀고 계속 시간초과가 나서 왜지왜지 하면서 이렇게 저렇게 계속 풀었는데.. Vertex 내에서 adjacents를 LinkedList로 해서 그랬던 거였고.. ArrayList로 해야 했던 것 같다. 인덱스 접근이 있어도 고

itdar.tistory.com

 

2021.04.26 - [Programming] - Git commit convention, 깃 커밋 컨벤션, How to commit, 커밋 메시지 포맷, Angular JS git commit message conventions

 

Git commit convention, 깃 커밋 컨벤션, How to commit, 커밋 메시지 포맷, Angular JS git commit message conventions

gist.github.com/stephenparish/9941e89d80e2bc58a153 AngularJS Git Commit Message Conventions AngularJS Git Commit Message Conventions. GitHub Gist: instantly share code, notes, and snippets. gist.git..

itdar.tistory.com

 

 

2021.04.21 - [Programming/SW Engineering , Architecture, etc.] - Software engineering 강의자료요약, Chapter5 System Modeling. Ian Sommerville, 소프트웨어공학, 강의자료요약, 아키텍처, architecture, Agile, 애자일, 방법론, plan driven, UML, modeling, requirements, 요구사항 분석

 

Software engineering 강의자료요약, Chapter5 System Modeling. Ian Sommerville, 소프트웨어공학, 강의자료요약,

ch5. System modeling 시스템 모델링은 시스템의 추상적인 모델들을 만드는 과정이고, 각 모델들은 시스템의 다른 관점을 표현한다. Unified Modeling Language (UML) graphical notation을 ..

itdar.tistory.com