UVa 10038/poj 2575/zoj 1879 Jolly jumpers (Water ver.)

Source: Internet
Author: User
Tags abs integer time limit

10038-jolly Jumpers

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=979

http://poj.org/problem?id=2575

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1879

A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive NTS 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 are to write a program to determine whether or not all of a number of sequences is a jolly jumper.

Input

Each line of input contains a integer n <= 3000 followed by n integers 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 3 5 1 4 2-1 6

Sample Output

Jolly not
Jolly

Note that there are two conditions that can exit the loop prematurely.

Complete code:

/*uva:0.012s*/
/*poj:16ms,184kb*/
/*zoj:0ms,204kb*/
  
#include <cstdio>
#include <cstring >
#include <cstdlib>
  
int arr[3010], vis[3010];
  
int main (void)
{
    int n, i;
    while (~SCANF ("%d", &n))
    {
        memset (vis, 0, sizeof (VIS));
        for (i = 0; i < n; i++)
            scanf ("%d", &arr[i]);
        BOOL flag = TRUE;
        for (i = 1; i < n; i++)
        {
            if (ABS (Arr[i]-arr[i-1]) >= N)
            {
                flag = false;
                break;
            if (Vis[abs (Arr[i]-arr[i-1])]++///Tips ~
            {
                flag = false;
                break;
            }
        }
        Puts (flag?) "Jolly": "Not Jolly");
    return 0;
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.