E - Jolly Jumpers

Posted Kiven#5197

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了E - Jolly Jumpers相关的知识,希望对你有一定的参考价值。

E - Jolly Jumpers
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit Status

Description

A 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

Each line of input contains an 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

难懂的题意。。(被题意坑了一发QAQ)

首先输入一个正整数n,后接n个数字,每连续的两个数字相减的绝对值组成1~n-1共n-1个数字。

AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<cstdlib>
 7 using namespace std;
 8 
 9 const int MAX=3050;
10 int a[MAX];
11 int b[MAX];
12 int n;
13 int main(){
14     while(~scanf("%d",&n)){
15         for(int i=0;i<n;i++){
16             scanf("%d",&a[i]);
17         }
18         if(n==1){//当n为1时直接输出 
19             printf("Jolly\n");
20             continue;
21         }
22         for(int i=1;i<n;i++){//两两相减的绝对值 
23             b[i]=abs(a[i]-a[i-1]);
24         }
25         int temp;
26         for(int i=1;i<n;i++){//冒泡排序 
27             for(int j=n-1;j>=i;j--){
28                 if(b[j]<b[j-1]){
29                     temp=b[j];
30                     b[j]=b[j-1];
31                     b[j-1]=temp;
32                 }
33             }
34         }
35         int ans=0;
36         for(int i=1;i<n;i++){//记录相等数字数 
37             if(b[i]==i)
38             ans++;
39         }
40         if(ans==n-1)
41         printf("Jolly\n");
42         else
43         printf("Not jolly\n");
44     }
45     return 0;
46 } 

 

以上是关于E - Jolly Jumpers的主要内容,如果未能解决你的问题,请参考以下文章

最大化这个方程 E[a1]-E[a2]+E[a3]-E[a4] [关闭]

make 模板

理解 e.clientX,e.clientY e.pageX e.pageY e.offsetX e.offsetY

理解 e.clientX,e.clientY e.pageX e.pageY e.offsetX e.offsetY

理解 e.clientX,e.clientY e.pageX e.pageY e.offsetX e.offsetY

理解 e.clientX,e.clientY e.pageX e.pageY e.offsetX e.offsetY