예제 #1
0
def deque_process(n):
    for i in range(1, n + 1):
        deque.append(i)

    while len(deque) != 1:
        a = deque.popleft()
        deque.rotate(-1)

    print(deque.popleft())
예제 #2
0
 def process_one(self, input):
     if input is self.null:
         return []
     
     coeff_k, ba, deque = self.data
     wn = input
     yn = 0
     for (b, a), w in izip(ba, deque):
         yn += b * w
         wn -= a * w
     yn += wn
     yn *= coeff_k
     deque.rotate(1)
     deque[0] = wn
     return [yn]
예제 #3
0
def doodledPassword(digits):
    n = len(digits)
    res = [deque(digits) for _ in range(n)]
    # print(res)

    # ! deque.rotate() and deque(iterable, maxlen)
    deque(map(lambda x: deque.rotate(x[1], -x[0]), enumerate(res)), 0)
    return [list(d) for d in res]
예제 #4
0
파일: MyStrategy.py 프로젝트: sshagy/cgdk
def synch_deque(deque, item, strict=None):
    # step or Point
    tmp = deque[0]
    if isinstance(tmp, tuple):
        # use step
        if not isinstance(item, tuple):
            # uzko!!!! [0]
            item = list(filter(lambda s: s[0] == item, deque))[0]
    else:
        # use point
        if not isinstance(item, Point):
            item = item[0]

    if item in deque:
        ind = deque.index(item)
        if -1 <= ind <= 1:
            deque.rotate(-ind)
    elif strict is None:
        pass
    elif strict:
        raise Exception(f'{item} is not contains in deque')
    else:
        # relevante rotate
        pass
예제 #5
0
from collections import deque

n, m = map(int, input().split())
out = map(int, input().split()) # not list type

deque = deque([i for i in range(1, n+1)])
result = 0

for i in out:
    left = deque.index(i)
    right = len(deque) - left
    print(left, right)
    if left < right:
        result += left
        deque.rotate(-left)
        deque.popleft()
    else:
        result += right
        deque.rotate(right)
        deque.popleft()
    print(result)
    
print("result = ", result)
예제 #6
0
def rotate(nums, k):
    from collections import deque

    deque = deque(nums)
    deque.rotate(k)
    print(list(deque))
예제 #7
0
# index(ele, beg, end)
print(deque.index(7,5,9))

print('Count')
print(deque.count(0))

print('Extend Left')
deque.extendleft([0])
print(deque)

print('Remove first occurence.')
deque.remove('abc')
print(deque)

print('Rotate by 2.')
deque.rotate(2)
print(deque)

print('Rotate left by 2.')
deque.rotate(-2)
print(deque)

print('Reverse.')
deque.reverse()
print(deque)





예제 #8
0
# 백준 프린터 큐

import sys
from collections import deque

test_num = int(input())

for _ in range(test_num):
    N, M = sys.stdin.readline().split()
    priority =deque(map(int,sys.stdin.readline().split()))
    order = 1

    while max(deque) != deque[int(M)]:
        while max(deque) != deque[0]:
            deque.rotate(-1)

        deque.popleft()
        order += 1

    print(order)


 def insert_nth(deque, n, x):
     deque.rotate(-n)
     deque.appendleft(x)
     deque.rotate(n)
예제 #10
0
# Link: https://leetcode.com/problems/reveal-cards-in-increasing-order/

# Approach: Reverse simulate the steps given. Sort the given deck array. Extract elements from tail and insert into a new deque() at beginning. But, before each insertion rotate the dequq() in
# right direction. Do this till you reach beginning of the deck and return the deque.

from collections import deque
'''
deque.rotate() works similar to following

def rotate(ans_array):
    if ans_array:
        el = ans_array.pop()
        ans_array.appendleft(el)
    return ans_array
'''


class Solution:
    def deckRevealedIncreasing(self, deck):
        self.ans_array = deque()
        deck.sort()

        for i in range(len(deck) - 1, -1, -1):
            elem = deck[i]

            self.ans_array.rotate()
            self.ans_array.appendleft(elem)

        return self.ans_array
예제 #11
0
# 문제 출처 : https://www.acmicpc.net/problem/1021

from sys import stdin
from collections import deque

n, p = map(int, stdin.readline().split())
arr = list(map(int, stdin.readline().split()))
deque = deque([i for i in range(1, n+1)])

count = 0

for num in arr:
    if deque[0] == num:
        deque.popleft()
        continue

    left_move = deque.index(num)
    right_move = len(deque) - left_move

    if left_move <= right_move:
        deque.rotate(-left_move)
        deque.popleft()
        count += left_move
    else:
        deque.rotate(right_move)
        deque.popleft()
        count += right_move

print(count)
예제 #12
0
    def rotate(self,x):
    	deque.rotate(self,x)
	if len(self)>0:
	    self[0].handle_head_of_queue()