POJ2575 ZOJ1879 UVA10038 Jolly Jumpers【序列】
2018-01-24 08:02
316 查看
Jolly Jumpers
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
Sample Output
Source
Waterloo local 2000.09.30
问题链接:POJ2575 ZOJ1879 UVA10038 Jolly Jumpers
问题简述:
每行输入n(n<=300)和n个整数,如果相邻的两个数之差正好是1到n-1之间的所有数,则输出“Jolly”,否则输出“Not jolly”。
问题分析:
需要标记数组diff[],标记已经出现的差值是否出现。其他都是套路。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C++语言程序如下:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 17815 | Accepted: 5383 |
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
Source
Waterloo local 2000.09.30
问题链接:POJ2575 ZOJ1879 UVA10038 Jolly Jumpers
问题简述:
每行输入n(n<=300)和n个整数,如果相邻的两个数之差正好是1到n-1之间的所有数,则输出“Jolly”,否则输出“Not jolly”。
问题分析:
需要标记数组diff[],标记已经出现的差值是否出现。其他都是套路。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C++语言程序如下:
/* POJ2575 ZOJ1879 UVA10038 Jolly Jumpers */ #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; const int N = 3000; int a ; bool diff ; bool check(int len) { memset(diff, false, sizeof(diff[0]) * len); for(int i=1; i<len; i++) { int d = abs(a[i] - a[i - 1]); if(d > len - 1 || d == 0 || diff[d]) return false; diff[d] = true; } return true; } int main() { int n; while(~scanf("%d", &n)) { for(int i=0; i<n; i++) scanf("%d", &a[i]); printf("%s\n", check(n) ? "Jolly" : "Not jolly"); } return 0; }
相关文章推荐
- UVa 10038 / POJ 2575 / ZOJ 1879 Jolly Jumpers (water ver.)
- uva10038 Jolly Jumpers
- zoj 1879 Jolly Jumpers
- UVA10038 Jolly Jumpers
- ZOJ Problem Set–1879 Jolly Jumpers
- POJ 2575 && ZOJ 1879 Jolly Jumper(整数序列)
- ZOJ 1879 Jolly Jumpers
- zoj 1879 Jolly Jumpers
- UVA10038 - Jolly Jumpers
- UVa 10038 Jolly Jumpers
- uva 10038 Jolly Jumpers
- uva 10038 Jolly Jumpers
- UVa 10038 - Jolly Jumpers
- zoj 1879 Jolly Jumpers
- ZOJ 1879 Jolly Jumpers
- UVa 10038 Jolly Jumpers
- zoj 1879 Jolly Jumpers
- UVA 10038 - Jolly Jumpers
- ZOJ 1879 — Jolly Jumpers(C++)
- POJ1083 HDU1050 ZOJ1029 UVALive2326 Moving Tables【序列+最值】