Luo Gu P1152 joyful jump
Title Description
A nn integer array elements, if the absolute value of the difference between two consecutive elements of the array comprises a [1, n-1] [1, n-1] between all integers, the called matching "joy jumping "the array of 14,231,423 matching" joy jump ", because the absolute value of difference are: 3,2,13,2,1.
Given an array, your task is to determine if the array is in line with "Happy jump."
Input Format
Each test line begins with an integer n (1 \ le n \ le 1000) n (1≤n≤1000), followed nn spaces spaced at [-10 ^ 8108 ^ 8-108,10 integer].
Output Format
For each test case, output one line if the array is in line with "joy jump" output "Jolly", otherwise output "Not jolly".
Sample input and output
Input # 1 copy
4 1 4 2 3
Output # 1
Jolly
Input # 2
5 1 4 2 -1 6
Output # 2
Not jolly
Description / Tips
\ (1 \ n \ the 10001≤n≤1000 \)
Violence, enumerated
a very violent water topic
This question actually has a solution to open two arrays and arrays of more than two
, but I think this question really only need to open an array is enough
to open a barrel, every record this number this number and the number in front of
these two numbers marked difference between true
after the entry is complete, the enumeration from 1 to n - 1 "joyful jump" If there are not really a barrel it does not meet
output not jolly and then return 0
Finally, if it is not the end of the output end of Jolly
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
bool a[100000005];
int main()
{
int n;
int now,last = 0;
scanf("%d",&n);
for(int i = 1;i <= n;++ i)
{
scanf("%d",&now);
a[abs(now - last)] = true;
last = now;
}
for(int i = 1;i < n;++ i)
{
if(a[i] != true)
{
cout << "Not jolly" << endl;
return 0;
}
}
cout << "Jolly" << endl;
return 0;
}