白駿#1966プリンタキュー


1.質問


https://www.acmicpc.net/problem/1966
  • Easy/Q、実施、グリンディ/25分

  • 2.私の回答


    2-1. に答える


    import sys
    
    n = int(sys.stdin.readline().split()[0])
    for i in range(n):
        doc_count, target = [int(x) for x in sys.stdin.readline().split()]
        list = [int(x) for x in sys.stdin.readline().split()]
        new_list = [{'index': index, 'value': value} for index, value in enumerate(list)]
        rlt = []
    
        while new_list:
            if new_list[0]['value'] == max([x['value'] for x in new_list]):
                rlt.append(new_list.pop(0))
            else:
                new_list.append(new_list.pop(0))
        count = 0
        for r in rlt:
            count += 1
            if r['index'] == target:
                break
        print(count)
    問題をよく読んで実施すればいいのですが、
    いつも間違っていて、時間しかかかりませんでした.
    ううう

    3.他人の回答


    test_case = int(input())
    
    for _ in range(test_case):
        n, m = list(map(int, input().split(' ')))
        queue = list(map(int, input().split(' ')))
        queue = [(i, idx) for idx, i in enumerate(queue)]
    
        count = 0
        while True:
            if queue[0][0] == max(queue, key=lambda x: x[0])[0]:
                count += 1
                if queue[0][1] == m:
                    print(count)
                    break
                else:
                    queue.pop(0)
            else:
                queue.append(queue.pop(0))

    4.感じ