题解:P1152 欢乐的跳
jym15063701069 · · 题解
P1152 欢乐的跳 题解
:::align{center}
>>>题目传送门<<<
:::
题目大意
给定
解题思路
将每两个连续元素之间差的绝对值放入数组
然后将
遍历
如果
说明不满足题目要求,
输出
否则满足题目要求,
输出
复杂度
时间复杂度:
::::success[这么简单的题就不用放代码了吧]
#include <bits/stdc++.h>
using namespace std;
/*====================*/
/*
P1152 欢乐的跳
*/
/*====================*/
using lnt = long long;
/*====================*/
const int INF = 0X3F3F3F3F;
/*====================*/
const int N = 1e3 + 10;
/*====================*/
int n;
lnt arr[N];
int delta[N]; //
/*====================*/
/*====================*/
void Solve(void)
{
// 输入
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> arr[i];
}
/*====================*/
// 求 delta 数组
for (int i = 1; i < n; ++i)
{
delta[i] = abs(arr[i] - arr[i + 1]);
}
/*====================*/
sort(delta + 1, delta + n); // 对 delta 数组排序
for (int i = 1; i < n; ++i) // 遍历 delta 数组
{
if (delta[i] != i) // 不符合题目要求,输出"Not jolly"
{
cout << "Not jolly";
return; // 结束程序
}
}
/*====================*/
cout << "Jolly"; // 程序未结束则说明满足题目要求,输出"Jolly"
}
/*====================*/
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int T = 1;
// cin>>T;
while (T--) Solve();
return 0;
}
::::
:::align{center}
养成随手点赞的好习惯
:::