zoukankan      html  css  js  c++  java
  • [HackerRank]New Year Chaos[UNDONE]

    Input (stdin)Download
    2
    8
    5 1 2 3 7 8 6 4
    8
    1 2 5 3 7 8 6 4
    Your Output (stdout)
    Too chaotic
    Too chaotic
    
    Expected OutputDownload
    Too chaotic
    7


    -------
    这题有问题吧,4如果要回到3的右边,一定要越过678 肯定超过和两个人交换的限制了,怎么可能是7呢?


    不成功的代码:
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    # Complete the minimumBribes function below.
    def sort(n,q):
        count = 0
    
        for i in range(n - 1):
            if q[i] < q[i + 1]:
                continue
            else:
                temp = q[i + 1]
                q[i + 1] = q[i]
                q[i] = temp
                count += 1
        return count
    
    def isDoable(n,q):
        orderList =[]
        for index in range(1,n+1):
            orderList.append(index)
    
        for index in range(n):
            if (abs(q[index] - orderList[index])) > 2 :
                return False
    
    def minimumBribes(n,q):
    
        if (isDoable(n,q) == False):
            return 'Too chaotic'
    
        countChange = 0
    
        while(all([q[i] < q[i + 1] for i in range(len(q) - 1)]) == False):
            countChange += sort(n, q)
        return countChange
    
    if __name__ == '__main__':
        t = int(input())
    
        for t_itr in range(t):
            n = int(input())
    
            q = list(map(int, input().rstrip().split()))
    
            print(minimumBribes(n ,q))



  • 相关阅读:
    文件系统
    用户
    Kali Linux命令(3)
    Kali Linux命令(2)
    Kali Linux命令(1)
    文件上传测试 bugku
    Seay源代码审计系统
    实验吧 BrainFuck
    zigbee学习之路(十一):看门狗
    zigbee学习之路(十):串口(接收)
  • 原文地址:https://www.cnblogs.com/alfredsun/p/10245999.html
Copyright © 2011-2022 走看看