[HackerRank]New Year Chaos[UNDONE]
2
8
5 1 2 3 7 8 6 4
8
1 2 5 3 7 8 6 4
Too chaotic
Too chaotic
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]的更多相关文章
- HackerRank "New Year Chaos"
Two tricks here: 1. Counting no. of inversed pairs - using Merge Sort, nothing special 2. How to che ...
- 日常小测:颜色 && Hackerrank Unique_colors
题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...
- HackerRank "Square Subsequences" !!!
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...
- 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 ...
- HackerRank "TBS Problem" ~ NPC
It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...
- 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 ...
- C++ Standard Template Library STL(undone)
目录 . C++标准模版库(Standard Template Library STL) . C++ STL容器 . C++ STL 顺序性容器 . C++ STL 关联式容器 . C++ STL 容 ...
- HackerRank Extra long factorials
传送门 今天在HackerRank上翻到一道高精度题,于是乎就写了个高精度的模板,说是模板其实就只有乘法而已. Extra long factorials Authored by vatsalchan ...
- HackerRank "Lucky Numbers"
Great learning for me:https://www.hackerrank.com/rest/contests/master/challenges/lucky-numbers/hacke ...
随机推荐
- WPS客户端更新日志留着备用
WPS Office (10.1.0.7520)==========================================新增功能列表------------WPS文字1 拼写检查:新增“中 ...
- angular部署到iis出现404解决方案
angular应用部署在iis上,刷新出现404 解决方案: 安装 iis URL Rewrite 模块,并在 src 目录下增加web.config,配置urlrewrite如下: <conf ...
- SQL Server -- 回忆笔记(五):T-SQL编程,系统变量,事务,游标,触发器
SQL Server -- 回忆笔记(五):T-SQL编程,系统变量,事务,游标,触发器 1. T-SQL编程 (1)声明变量 declare @age int (2)为变量赋值 (3)while循环 ...
- Jenkins+git+gitlab实现持续自动集成部署
1 实验环境 三台服务器 gitlab 192.168.7.139 Jenkins 192.168.7.140 java 192.168.7.141 [root ...
- Redis学习笔记(5)——Redis数据持久化
出处http://www.cnblogs.com/xiaoxi/p/7065328.html 一.概述 Redis的强大性能很大程度上都是因为所有数据都是存储在内存中的,然而当Redis重启后,所有存 ...
- python Socket socketserver
Socket 套接字 socket的 类型 实现socket对象时传入 到socket 类中 socket.AF_INET 服务器间的通讯 IPv4 socket.AF_INET6 IPv6 sock ...
- python基础-小练习
三级菜单 要求: 打印省.市.县三级菜单 可返回上一级 可随时退出程序 购物车程序 要求: 用户名和密码存放于文件中,格式为:egon|egon123 启动程序后,先登录,登录成功则让用户输入工资,然 ...
- koa2源码解读及实现一个简单的koa2框架
阅读目录 一:封装node http server. 创建koa类构造函数. 二:构造request.response.及 context 对象. 三:中间件机制的实现. 四:错误捕获和错误处理. k ...
- KVM架构及模块简介
1.简介 2.架构 3.KVM模块及QEMU 一.简介 KVM(Kernel Virtual Machine)基于内核的虚拟机.阿维·齐维迪(Avi Kivity)在一家名为Qumranet的初创企业 ...
- xgboost 参数调优指南
一.XGBoost的优势 XGBoost算法可以给预测模型带来能力的提升.当我对它的表现有更多了解的时候,当我对它的高准确率背后的原理有更多了解的时候,我发现它具有很多优势: 1 正则化 标准GBDT ...