E-jolly Jumpers

Source: Internet
Author: User
E-jolly Jumpers Time limit:3000 Ms Memory limit:0 KB 64bit Io format:% LLD & % llusubmit status

Description

A sequenceN> 0Integers is calledJolly JumperIf the absolute values of the difference between successive elements take on all the values 1 throughN-1. For instance,

1 4 2 3

Is a Jolly Jumper, because the absolutes differences are 3, 2, and 1 respectively. the definition implies that any sequence of a single integer is a Jolly Jumper. you are to write a program to determine whether or not each of a number of sequences is a Jolly Jumper.

Input

Each line of input contains an integerN<= 3000 followedNIntegers representing the sequence.

Output

For each line of input, generate a line of output saying "Jolly" or "not jolly ".

Sample Input

4 1 4 2 35 1 4 2 -1 6

Sample output

JollyNot jolly

Difficult to understand .. (Qaq was thrown into question)

First, enter a positive integer N, followed by N numbers, and the absolute values of each two consecutive digits subtract Form 1 ~ N-1 digits in n-1.

AC code:

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <cmath> 6 # include <cstdlib> 7 using namespace std; 8 9 const int max = 3050; 10 int A [Max]; 11 int B [Max]; 12 INT N; 13 int main () {14 While (~ Scanf ("% d", & N) {15 for (INT I = 0; I <n; I ++) {16 scanf ("% d ", & A [I]); 17} 18 if (n = 1) {// when n is 1, 19 printf ("Jolly \ n") is output directly; 20 continue; 21} 22 for (INT I = 1; I <n; I ++) {// the absolute values of the two pairs subtract 23 B [I] = ABS (A [I]-A [I-1]); 24} 25 int temp; 26 for (INT I = 1; I <n; I ++) {// bubble sort 27 for (Int J = n-1; j> = I; j --) {28 If (B [J] <B [J-1]) {29 temp = B [J]; 30 B [J] = B [J-1]; 31 B [J-1] = temp; 32} 33} 34} 35 int ans = 0; 36 for (INT I = 1; I <n; I ++) {// number of equal records 37 If (B [I] = I) 38 ans ++; 39} 40 if (ANS = N-1) 41 printf ("Jolly \ n"); 42 else43 printf ("not jolly \ n"); 44} 45 return 0; 46}

 

E-jolly Jumpers

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.