Problem A: Jolly Jumpers

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 10  Solved: 4
[Submit][Status][Web Board]

Description

A sequence of n > 0 integers is called a jolly jumper if the absolute values of the differences between successive elements take on all possible values 1 through n - 1. For instance, 1 4 2 3 is a jolly jumper, because the absolute differences are 3, 2, and 1, respectively. The definition implies that any sequence of a single integer is a jolly jumper. Write a program to determine whether each of a number of sequences is a jolly jumper.

Input

Each line of input contains an integer n < 3, 000 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

    - 

Sample Output

Jolly
Not jolly

HINT

poj2575


  水题。

  这道题要求输入一串整型数,第一个数为n,后面接着有n个int数,要求后面这n个数两两之间差的绝对值在[1,n-1]范围内,且差的绝对值不能重复。

  虽是水题,但还是纠结了一会,原因还是没有读懂题意,忽略了第二个条件。由此可见,英语阅读能力的重要性!

My code:

 #include <iostream>

 using namespace std;

 int abs(int n)
{
return n>?n:-n;
}
int main()
{
int n;
int ab;
int i;
int a[];
while(cin>>n){
bool b[]={}; //记录绝对值差有无重复
for(i=;i<n;i++){ //输入
cin>>a[i];
}
for(i=;i<n;i++){ //循环判断
int t=abs(a[i]-a[i-]);
if(!(<=t && t<=n-) || b[t] )
break;
else{
b[t]=true;
}
}
if(i==n) //如果正常跳出,说明是个Jolly
cout<<"Jolly"<<endl;
else{
cout<<"Not jolly"<<endl;
}
}
return ;
}

Freecode : www.cnblogs.com/yym2013

最新文章

  1. x01.Tetris: 俄罗斯方块
  2. 【从零开始学习Hadoop】--1.Hadoop的安装
  3. 使用Python解析JSON数据的基本方法
  4. s5pv210 cpu运行debian
  5. dba诊断之lock
  6. sublime相关设置
  7. kafka配额控制
  8. C++继承:公有,私有,保护
  9. 浅谈Mybatis(三)
  10. 浅析Web缓存
  11. JavaScript创建对象的方法
  12. [51nod1709]复杂度分析
  13. cannot open file &quot;cxcore.lib&quot;
  14. Git之(五)远程管理
  15. flutter 监听返回键
  16. 【记录】Windows 操作系统常用快捷命令
  17. Java获取客户端真实IP
  18. tornado 初解
  19. Python选修课第一届Turtle绘图大赛田康林赵冰珂组
  20. opencv学习笔记(五)

热门文章

  1. ppa安装php版本
  2. linux5
  3. 锋利的jQuery-7--编写插件基础知识
  4. Java基础之理解Annotation(与@有关,即是注释)
  5. php-fpm.conf两个至关重要的参数
  6. ctags 的最简单使用
  7. Node.js 究竟是什么
  8. 《PHP程序设计》读书笔记
  9. ORACLE10G工作原理
  10. mysql如何用order by 自定义排序