洛谷——P1152 歡樂的跳
阿新 • • 發佈:2017-11-20
not sample radius 連續 個數 tdi pac 絕對值 esp
P1152 歡樂的跳
題目描述
一個n個元素的整數數組,如果數組兩個連續元素之間差的絕對值包括了[1,n-1]之間的所有整數,則稱之符合“歡樂的跳”,如數組1 4 2 3符合“歡樂的跳”,因為差的絕對值分別為:3,2,1。
給定一個數組,你的任務是判斷該數組是否符合“歡樂的跳”。
輸入輸出格式
輸入格式:
每組測試數據第一行以一個整數n(1<=n<=1000)開始,接下來n個空格隔開的在[-108,108]之間的整數。
輸出格式:
對於每組測試數據,輸出一行若該數組符合“歡樂的跳”則輸出"Jolly",否則輸出"Not jolly"。
輸入輸出樣例
輸入樣例#1: 復制輸入樣例1: 4 1 4 2 3 輸入樣例2: 5 1 4 2 -1 6輸出樣例#1: 復制
輸出樣例1: Jolly 輸出樣例2: Not jolly
說明
1<=n<=1000
#include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define N 1010 using namespace std;int n,a[N]; bool flag,vis[N]; int read() { int x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘) x=x*10+ch-‘0‘,ch=getchar(); return x*f; } int main() { n=read(); for(int i=1;i<=n;i++) a[i]=read(); for(int i=2;i<=n;i++) { vis[abs(a[i]-a[i-1])]=true; if(abs(a[i]-a[i-1])>=n) {flag=true;break;} } for(int i=1;i<n;i++) if(!vis[i]){flag=true;break;} if(flag) printf("Not jolly"); else printf("Jolly"); return 0; }
洛谷——P1152 歡樂的跳