07: Funny Jumps
-
Total time limit:
-
1000ms
-
Memory Limit:
-
65536kB
-
Describe
-
An "interesting jump" in a sequence of length n (n>0) is currently only available when the absolute value of the difference between adjacent elements is sorted from 1 to (n-1). For example, 1 4 2 3 has a "fun jump" because the absolute value of the difference is 3,2,1. Of course, any sequence that contains only a single element must have a "fun jump". You need to write a program that determines whether a given sequence has a "funny jump".
-
Input
-
A row, the first number is n (0 < n < 3000), is the sequence length, followed by n integers, followed by each element in sequence, the absolute value of each element does not exceed 1,000,000,000.
-
Output
-
Row, if the sequence has "interesting jumps", output "Jolly", otherwise output "not Jolly".
-
Sample input
-
4 1 4) 2 3
-
Sample output
-
Jolly
-
Source
-
Waterloo local 2000.09.30
Ideas:
Simulation
Come on, on the code:
#include <cmath>#include<cstdio>#include<iostream>#include<algorithm>using namespacestd;intN;Long Long intai[3001],bi[3001];intMain () {scanf ("%d",&N); if(n==1) {printf ("jolly\n"); return 0; } for(intI=1; i<=n;i++) scanf ("%lld",&Ai[i]); for(intI=1; i<n;i++) Bi[i]=abs (ai[i+1]-Ai[i]); Sort (bi+1, bi+N); for(intI=1; i<n;i++) { if(bi[i]!=i) {printf ("Not jolly\n"); return 0; }} printf ("jolly\n"); return 0;}
AC Diary--Fun jumping Openjudge 1.6 07