【poj2575】Jolly Jumpers
2015-11-22 16:37
393 查看
【poj2575】Jolly Jumpers
DescriptionA 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
Source
Waterloo local 2000.09.30
【代码】
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; int n,m; bool pd; int a[5000]; bool b[5000]; int main(){ while (~scanf("%d",&n)){ for (int i=1;i<=n;++i) scanf("%d",&a[i]); memset(b,0,sizeof(b)); for (int i=2;i<=n;++i){ m=abs(a[i]-a[i-1]); b[m]=true; } pd=true; for (int i=1;i<n;++i) if (!b[i]){ pd=false; break; } if (pd) printf("Jolly\n"); else printf("Not jolly\n"); } }
相关文章推荐
- Maximum Depth of Binary Tree (Leet Code)
- webview返回按钮 iOS
- 在ubuntu下安装python imagine library
- 网页元素位置、鼠标事件位置信息小结
- 如何使用富文本编辑器xheditor
- HDU1029-Ignatius and the Princess IV
- Android应用内语言切换实现
- 自定义控件SettingItemView
- zzulioj 1783: 简单的求和 (筛选求和) 求和预处理 好题
- SQLite使用事务更新—by command
- 《你的灯亮着吗?:发现问题的真正所在》读书笔记
- HTML表格边框的设置小技巧
- CALayer 为什么选择 cg 开头 而 不选择 UI 开头
- jsp页面、servlet显示中文乱码详解
- ETL浅谈
- Assets目录下的文件大小是否有限制?
- 【C++基础学习】成员对象与对象数组
- 杭电ACM1162(prim)
- Android的进程线程
- HDU1877-又一版 A+B