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代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std; const int MAX=;
int a[MAX];
int b[MAX];
int n;
int main(){
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
if(n==){//当n为1时直接输出
printf("Jolly\n");
continue;
}
for(int i=;i<n;i++){//两两相减的绝对值
b[i]=abs(a[i]-a[i-]);
}
int temp;
for(int i=;i<n;i++){//冒泡排序
for(int j=n-;j>=i;j--){
if(b[j]<b[j-]){
temp=b[j];
b[j]=b[j-];
b[j-]=temp;
}
}
}
int ans=;
for(int i=;i<n;i++){//记录相等数字数
if(b[i]==i)
ans++;
}
if(ans==n-)
printf("Jolly\n");
else
printf("Not jolly\n");
}
return ;
}

E - Jolly Jumpers的更多相关文章

  1. 烟大 Contest1025 - 《挑战编程》第二章:数据结构 Problem A: Jolly Jumpers(水题)

    Problem A: Jolly Jumpers Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 10  Solved: 4[Submit][Status] ...

  2. uva 10038 - Jolly Jumpers

    #include <iostream> #include <cstdio> #include <stdlib.h> using namespace std; ], ...

  3. Zerojudge解题经验交流

    题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...

  4. OpenJudge解题经验交流

    1.1编程基础之输入输出01:Hello, World! 02:输出第二个整数PS:a,b需用longint类型接收 03:对齐输出 04:输出保留3位小数的浮点数 05:输出保留12位小数的浮点数 ...

  5. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  6. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  7. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  8. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  9. C语言中函数声明实现的位置

    在学习C语言的时候我遇到了这么个事情,因为之前先学习的C#,在C#编译器中,函数的声明位置不会影响编译的结果,但是在C语言中却发生了错误 先看一段代码: #include <stdio.h> ...

随机推荐

  1. linux c语言 select函数使用方法

    linux c语言 select函数使用方法 表头文件 #i nclude<sys/time.h> #i nclude<sys/types.h> #i nclude<un ...

  2. 【Sprint3冲刺之前】日历表的事件处理和管理(刘铸辉)

    我的Sprint2冲刺——日历表的事件处理和管理(刘铸辉,刘静) 我的Sprint2冲刺计划领到的任务是和静姐结对编程,完成日历表的事件处理和管理,下面详细讲解下技术细节. 1.设计结构图 首先要画出 ...

  3. laravel 将数组转化成字符串 再把字符串转化成数组

    这是在给阮少翔改代码的时候用的方法, 开始的数据用explored转化成数组不是想要的结果, 我就自己写了一个方法把有用的信息提取出来拼接成一个字符串, 再用explored将字符串转化成数组.   ...

  4. Linux多线程编程的条件变量

    在stackoverflow上看到一关于多线程条件变量的问题,题主问道:什么时候会用到条件变量,mutex还不够吗?有个叫slowjelj的人做了很好的回答,我再看这个哥们其他话题的一些回答,感觉水平 ...

  5. JSON和JSONP 傻傻分不清楚?

    什么是JSON  前面简单说了一下,JSON是一种基于文本的数据交换方式,或者叫做数据描述格式,你是否该选用他首先肯定要关注它所拥有的优点. JSON的优点: 1.基于纯文本,跨平台传递极其简单: 2 ...

  6. ubuntu 下的中文输入法的安装和配置- ibus

    ibus输入法 Chinese语言包安装 首先需要给Ubuntu16.04安装Chinese语言包支持.  如上图点击其中的Install/Remove Languages…,这个对话框是通过syst ...

  7. beyond compare添加右键快捷方式

    如果安装beyond compare后,右键不能出现比较选项,可以通过设置 beyond compare完成. 选择 工具->选项,在资源管理器整合下面,有一个在资源管理器关联菜单中显示beyo ...

  8. poj1125--Floyd

    题解: 有N个股票经济人能够互相传递消息.他们之间存在一些单向的通信路径.如今有一个消息要由某个人開始传递给其它全部人.问应该由哪一个人来传递,才干在最短时间内让全部人都接收到消息. 显然,用Floy ...

  9. Android 调用QQ登录

    调用QQ登录        在如今的项目开发.调用第三方登录.差点儿是必须的,而调用QQ登录也是不可缺少的,这里把相关代码分享出来,希望能拿去就能够用,降低项目开发的时间.希望对大家实用. 1,去QQ ...

  10. 九度OJ 1135:字符串排序 (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1559 解决:807 题目描述: 先输入你要输入的字符串的个数.然后换行输入该组字符串.每个字符串以回车结束,每个字符串少于一百个字符. 如 ...