07: Interesting jump, 07: Interesting jump

Source: Internet
Author: User

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 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.