原题链接 https://www.luogu.com.cn/problem/P1152
题目描述
若长度为 n 的序列中,相邻两数的绝对差恰好把 1 到 n−1 各取一次,则称它为“欢乐的跳”。
输入 每组数据先给出长度 n,再给出 n 个整数。
输出 每组一行,符合条件输出 Jolly,否则输出 Not jolly。
输入输出样例 1
输入
4 1 4 2 3输出
Jolly输入输出样例 2
输入
5 1 4 2 -1 6输出
Not jolly题解
n,*g=map(int,open(0).read().split())
a=[0]*n
s=0
for i in range(n-1):
diff=abs(g[i]-g[i+1])
if 1<=diff<=n-1:
a[diff-1]+=1
else:
print("Not jolly")
break
if a[diff-1]==1:
s+=1
else:
print("Not jolly")
break
if s==n-1:
print("Jolly")