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))

[HackerRank]New Year Chaos[UNDONE]的更多相关文章

  1. HackerRank "New Year Chaos"

    Two tricks here: 1. Counting no. of inversed pairs - using Merge Sort, nothing special 2. How to che ...

  2. 日常小测:颜色 && Hackerrank Unique_colors

    题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...

  3. HackerRank "Square Subsequences" !!!

    Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...

  4. HackerRank "Minimum Penalty Path"

    It is about how to choose btw. BFS and DFS. My init thought was to DFS - TLE\MLE. And its editorial ...

  5. HackerRank "TBS Problem" ~ NPC

    It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...

  6. IIS FTP Server Anonymous Writeable Reinforcement, WEBDAV Anonymous Writeable Reinforcement(undone)

    目录 . 引言 . IIS 6.0 FTP匿名登录.匿名可写加固 . IIS 7.0 FTP匿名登录.匿名可写加固 . IIS >= 7.5 FTP匿名登录.匿名可写加固 . IIS 6.0 A ...

  7. C++ Standard Template Library STL(undone)

    目录 . C++标准模版库(Standard Template Library STL) . C++ STL容器 . C++ STL 顺序性容器 . C++ STL 关联式容器 . C++ STL 容 ...

  8. HackerRank Extra long factorials

    传送门 今天在HackerRank上翻到一道高精度题,于是乎就写了个高精度的模板,说是模板其实就只有乘法而已. Extra long factorials Authored by vatsalchan ...

  9. HackerRank "Lucky Numbers"

    Great learning for me:https://www.hackerrank.com/rest/contests/master/challenges/lucky-numbers/hacke ...

随机推荐

  1. LEDAPS1.3.0版本移植到windows平台----HuPm参数初始化模块

    这个是2012年左右放在百度空间的,谁知百度空间关闭...转移到博客园. 最近项目用到3.1.2版本的LEDAPS,新版本的使用情况会在后续文章中慢慢丰富. LEDAPS的调用顺序是:HuPm--&g ...

  2. Dynamics AX 2012 R2 电子邮件广播错误 0x80040213

    Dynamics AX 2012 R2 电子邮件广播错误 0x80040213 今天Reinhard在新环境做邮件广播测试时,发现无法发送邮件,并报以下错误: 类"CDO.Message&q ...

  3. Android远程桌面助手(Build 0787)

    Android远程桌面助手(Build 0787) 新增: 增加了输入法的快速切换功能,支持通过Google拼音输入法在PC端快速输入中文: 增加了Broadcast的暂停和继续功能: 某些应用截屏失 ...

  4. fiddler几种功能强大的用法

    参考网址: http://caibaojian.com/fiddler.html http://www.cnblogs.com/tangdongchu/p/4178552.html 1.fiddler ...

  5. javascript弹出模态窗体

    function openwindow(url,name,iWidth,iHeight){ //获得窗口的垂直位置 var iTop = (window.screen.availHeight-30-i ...

  6. css3新特性合集

    转自:https://www.cnblogs.com/xiaoxie2016/p/5964694.html (若原作者对此转载有疑问,联系删除,谢谢!) animation    IE10 anima ...

  7. vue 用less

    https://blog.csdn.net/u013746071/article/details/79655042

  8. 实战申请Let's Encrypt永久免费SSL证书过程教程及常见问题

    最近需要https这里看到一份不错的博客,收录一下! Let's Encrypt作为一个公共且免费SSL的项目逐渐被广大用户传播和使用,是由Mozilla.Cisco.Akamai.IdenTrust ...

  9. SpringBoot打包成war

    关于SpringBoot打成jar包以及jar包如何在Linux持久运行,我在前面已经说过了,所以本次不再赘述. 关于SpringBoot打包成war,其实步骤特别简单,如下图所示(如果是jar,通常 ...

  10. easyui-tab标签

    一. 加载方式 //class 加载方式<div id="box" class="easyui-tabs" style="width:500px ...