[MM22-易] Jolly Jumpers
Problem DescriptionA sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-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 File Format
Each line of input contains an integer n <= 3000 followed by n integers representing the sequence.
Output Format
For each line of input, generate a line of output saying "Jolly" or "Not jolly".
Example
Input File Format
Each line of input contains an integer n <= 3000 followed by n integers representing the sequence.
Output Format
For each line of input, generate a line of output saying "Jolly" or "Not jolly".
Example
Sample Input: | Sample Output: |
4 1 4 2 3 5 1 4 2 -1 6 | Jolly Not jolly |
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- using namespace std;
- int main(){
- int n;
- int jolly[3005];
- bool jollyp = 1;
- while( scanf( "%d", &n ) != EOF )
- {
- bool jump[3005] = {0};
- jollyp = 1;
- for( int i = 0 ; i < n ; i++ )
- {
- scanf( "%d", &jolly[i] );
- }
- for( int i = 1 ; i < n ; i++ )
- {
- if( abs(jolly[i] - jolly[i-1]) >= n ||
- abs(jolly[i] - jolly[i-1]) <= 0 ||
- jump[abs(jolly[i] - jolly[i-1])] )
- {
- jollyp = 0;
- break;
- }
- jump[abs(jolly[i] - jolly[i-1])] = 1;
- }
- if( jollyp )
- printf( "Jolly\n" );
- else
- printf( "Not jolly\n" );
- }
- return 0;
- }
沒有留言:
張貼留言