AC Diary--Fun jumping Openjudge 1.6 07

Source: Internet
Author: User

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

Related Article

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.