标签:style bsp 长度 程序 第一个 存在 序列 name i++
一个长度为n(n>0)的序列中存在“有趣的跳跃”当前仅当相邻元素的差的绝对值经过排序后正好是从1到(n-1)。例如,1 4 2 3存在“有趣的跳跃”,因为差的绝对值分别为3,2,1。当然,任何只包含单个元素的序列一定存在“有趣的跳跃”。你需要写一个程序判定给定序列是否存在“有趣的跳跃”。
4 1 4 2 3
Jolly
代碼實現:
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 int n,a,b,c; 5 bool v[6000]; 6 int main(){ 7 scanf("%d%d",&n,&a); 8 for(int i=1;i<n;i++){ 9 scanf("%d",&b); 10 c=max(a-b,b-a); 11 if(c>5000){printf("Not jolly\n");return 0;} 12 if(v[c]){printf("Not jolly\n");return 0;} 13 v[c]=1;a=b; 14 } 15 for(int i=1;i<n;i++) if(!v[i]){printf("Not jolly\n");return 0;} 16 printf("Jolly\n"); 17 return 0; 18 }
。。。
标签:style bsp 长度 程序 第一个 存在 序列 name i++
原文地址:http://www.cnblogs.com/J-william/p/6155129.html