목록큐 (17)
넘치게 채우기
https://www.acmicpc.net/problem/2161BOJ - 카드 1문제 유형: 큐, 구현문제 난이도: Silver V시간 제한: 1초메모리 제한: 128MB 문제N장의 카드가 있다. 각각의 카드는 차례로 1부터 N까지의 번호가 붙어 있으며, 1번 카드가 제일 위에, N번 카드가 제일 아래인 상태로 순서대로 카드가 놓여 있다.이제 다음과 같은 동작을 카드가 한 장 남을 때까지 반복하게 된다. 우선, 제일 위에 있는 카드를 바닥에 버린다. 그 다음, 제일 위에 있는 카드를 제일 아래에 있는 카드 밑으로 옮긴다.예를 들어 N=4인 경우를 생각해 보자. 카드는 제일 위에서부터 1234 의 순서로 놓여있다. 1을 버리면 234가 남는다. 여기서 2를 제일 아래로 옮기면 342가 된다. 3을 버리면..
https://www.acmicpc.net/problem/6514BOJ - Expressions문제 유형: 스택, 큐, 트리문제 난이도: Silver I시간 제한: 1초메모리 제한: 128MB 문제Arithmetic expressions are usually written with the operators in between the two operands (which is called infix notation). For example, (x+y)*(z-w) is an arithmetic expression in infix notation. However, it is easier to write a program to evaluate an expression if the expression is writ..
https://leetcode.com/problems/design-circular-deque/description/?envType=daily-question&envId=2024-09-28leetcode - Design Circular Deque문제 유형 : 데크, 큐, 스택, 구현문제 난이도 : Medium 문제Design your implementation of the circular double-ended queue (deque).Implement the MyCircularDeque class:MyCircularDeque(int k) Initializes the deque with a maximum size of k.boolean insertFront() Adds an item at the front..
https://leetcode.com/problems/reveal-cards-in-increasing-order/description/ Leetcode - Reveal Cards In Increasing Order 문제 유형 : 스택, 큐 문제 난이도 : Medium 문제 You are given an integer array deck. There is a deck of cards where every card has a unique integer. The integer on the ith card is deck[i]. You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in o..
https://leetcode.com/problems/time-needed-to-buy-tickets/description/ LeetCode - Time Needed to Buy Tickets 문제 유형 : 큐 문제 난이도 : Easy 문제 There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line. You are given a 0-indexed integer array tickets of length n where the number of tickets that the ith person ..
https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/description/ Leetcode - Number of Students Unable to Eat Lunch 문제 유형 : 스택, 큐 문제 난이도 : Easy 문제 The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches. The number of sandwiches ..
스택은 LIFO, 큐는 FIFO 자료구조이다. 어떻게 하면 두 개의 스택으로 하나의 큐를 구현하는데, 대부분의 경우에서 O(1)으로 구현할 수 있을까? 하나를 입력용 스택, 하나를 출력용 스택이라고 해보자. 입력용 스택은 입력만 받는다. 출력용 스택은 출력만 한다. 단, 출력용 스택이 empty인 경우, 입력용 스택의 원소들을 pop하여 출력용 스택에 push하면 된다. 이때 출력용 스택에는 입력의 역순으로 들어오게 되어 기존의 출력 순서가 반대로 되어 FIFO가 된다. 이 경우만 제외하고는, O(1)의 시간복잡도를 가진다. class MyQueue { stack i,o; public: MyQueue() { } void push(int x) { i.push(x); } int pop() { int x; i..
https://leetcode.com/problems/implement-queue-using-stacks/description/?envType=daily-question&envId=2024-01-29 LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com LeetCode - Implement Queue using Stacks 문제 유형 : 스택/큐 문제 난이도 : E..
https://school.programmers.co.kr/learn/courses/30/lessons/118667# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 프로그래머스 - 두 큐 합 같게 만들기 문제 유형 : 큐 문제 난이도 : Level 2 문제 설명 길이가 같은 두 개의 큐가 주어집니다. 하나의 큐를 골라 원소를 추출(pop)하고, 추출된 원소를 다른 큐에 집어넣는(insert) 작업을 통해 각 큐의 원소 합이 같도록 만들려고 합니다. 이때 필요한 작업의 최소 횟수를 구하고자 합니다. 한 번의 pop과 한 번의 insert를 합쳐서 작업을 1..
https://school.programmers.co.kr/learn/courses/30/lessons/159993 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 유형 : 큐 , 구현 문제 난이도 : Level 2 문제 설명 호텔을 운영 중인 코니는 최소한의 객실만을 사용하여 예약 손님들을 받으려고 합니다. 한 번 사용한 객실은 퇴실 시간을 기준으로 10분간 청소를 하고 다음 손님들이 사용할 수 있습니다. 예약 시각이 문자열 형태로 담긴 2차원 배열 book_time이 매개변수로 주어질 때, 코니에게 필요한 최소 객실의 수를 return 하는 sol..