[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 ...
随机推荐
- Android Studio 代码无提示,无颜色区分
一.问题 ①java代码没有颜色区分,统一黑色 ②代码不会联想提示,原来打前几个字母便会联想到后面的内容 二.解决 打开File,将Power save Mode的勾勾去掉
- Broadcast发送广播
一.知识介绍 1.[广播分类] ①有序广播:接收者A收到广播传递给B,B传给C,有序传递.任何一个环节都可以终止广播,也可以修改广播中携带的数据. 发送的方式:sendOrderedBroadcast ...
- QT获取本机IP和Mac地址
#include <QNetworkInterface> #include <QList> void MainWindow::getIPPath() { QString str ...
- python读取txt文件最后一行(文件大+文件小)
txt文件小 #coding:utf-8 ''' fname为所读xx.txt文件 输出为:文件第一行和最后一行 ''' fname = 'test.txt' with open(fname, 'r' ...
- ServiceStack.Redis连接阿里云redis服务时使用连接池出现的问题
创建连接池 private static PooledRedisClientManager prcm = CreateManager(new string[] { "password@ip: ...
- LeetCode算法题-To Lower Case(Java实现)
这是悦乐书的第301次更新,第320篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第169题(顺位题号是709).实现具有字符串参数str的函数ToLowerCase() ...
- pymsql模块
老师的博客地址:http://www.cnblogs.com/wupeiqi/articles/5713330.html 通过pymysql 模块可以通过朋友去操作mysql 数据库,首先的在pip上 ...
- Redis学习笔记(3)——Redis的命令大全
Redis是一种nosql数据库,常被称作数据结构服务器,因为值(value)可以是 字符串(String), 哈希(Map), 列表(list), 集合(sets) 和 有序集合(sorted se ...
- springboot mybatis搭建
非常easy直接写,没有搭建成分 1.目录 2. @RestController public class UserController { @RequestMapping("/hello& ...
- Linux内核入门到放弃-时间管理-《深入Linux内核架构》笔记
低分辨率定时器的实现 定时器激活与进程统计 IA-32将timer_interrupt注册为中断处理程序,而AMD64使用的是timer_event_interrupt.这两个函数都通过调用所谓的全局 ...