当前位置:网站首页>Codeforce:b. difference array [optimization of prefix 0]
Codeforce:b. difference array [optimization of prefix 0]
2022-07-19 15:57:00 【White speed Dragon King's review】

analysis
If you don't need to sort It is a simple combinatorial number problem
Now is the simulation of violence
However, Prefix 0 Many and useless
So we maintain a wave of prefixes independently 0
You don't have to do it when sorting
ac code
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
# we use the 0's at the beginning to optimize
x = []
while len(a) > 1:
tmp = []
for i in range(1, len(a)):
if a[i] - a[i - 1] == 0:
x.append(0)
else:
tmp.append(a[i] - a[i - 1])
b = []
if x:
b = [0]
x.pop()
a = b + sorted(tmp)
print(*a)
summary
The skill of doing questions is to look at examples
Found that there are many prefixes 0
Just think of ignoring them
About their maintenance, we need to add an extra list Let's see their number
Pop up one at a time , If there is any more, it should be included
边栏推荐
猜你喜欢
随机推荐
2022-7-17
MySQL series "trigger details"
Radiotap
离线安装mariadb
2022-7-17
ORACLE中行锁问题排查手段
智牛股--08
云原生—编排及管理
投资的意义
Caddy's introduction
Advanced C language - struct implementation bit segment
lambda函数以及对 items.sort(key = lambda y:y[1], reverse = True) 的理解。
QT | qcombobox of control
Windows install MySQL
Argument list too long 原因与解决思路
cookie,localstorage封装
Griddlyjs: Web ide based on Reinforcement Learning
Adn public welfare acceleration - jsdelivr NPM (domestic), a high-quality alternative to elmcdn
Hash table related knowledge
C语言力扣第34题之在排序数组中查找元素的第一个和最后一个位置。两种方法









