07: Interesting jump, 07: Interesting jump
07: Interesting jumps
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
There is an "interesting jump" in a sequence with a length of n (n> 0). Currently, only when the absolute values of the adjacent elements are sorted exactly from 1 to (n-1 ). For example, 1 4 2 3 has an interesting jump because the absolute values of the difference are 3, 2, and 1. Of course, any sequence containing only a single element must have an "interesting jump ". You need to write a program to determine whether a given sequence has an "interesting jump ".
-
Input
-
For a row, the first number is n (0 <n <3000), which is the sequence length. Next there are n integers, which are the elements in the sequence. The absolute values of each element cannot exceed 1,000,000,000.
-
Output
-
A row. If there is an "interesting jump" in the sequence, "Jolly" is output; otherwise, "Not jolly" is output ".
-
Sample Input
-
4 1 4 2 3
-
Sample output
-
Jolly
-
Source
-
Waterloo local 200000009.30
-
1 #include<iostream> 2 #include<cmath> 3 #include<cstdio> 4 #include<cstring> 5 #include<algorithm> 6 using namespace std; 7 int a[10001]; 8 int b[10001]; 9 int main()10 {11 int n;12 cin>>n;13 for(int i=1;i<=n;i++)14 {15 cin>>a[i];16 }17 for(int i=1;i<=n-1;i++)18 {19 b[i]=abs(a[i]-a[i+1]);20 }21 sort(b+0,b+n);22 for(int i=1;i<=n-1;i++)23 {24 if(b[i]!=i)25 {26 cout<<"Not jolly";27 return 0;28 }29 }30 cout<<"Jolly";31 return 0;32 }