N個數的數列中,(1,2,3...,N-1)這些值都要被兩數字的差值涵蓋到,從Example來說,(1,4,2,3)的差值分別為(3,2,1),所以有涵蓋(1~3),因此為Jolly,(1,4,2,-1,6)的差值為(3,2,3,5)沒有涵蓋(1~5)所以不是Jolly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cmath> | |
using namespace std; | |
int main() | |
{ | |
// freopen("input.txt","rt",stdin); | |
int N; | |
while (scanf("%d",&N)!=EOF){ | |
int s[3001],check[3001]={0}; | |
bool ok=1; | |
scanf("%d",&s[0]); | |
for (int i=1; i<N; i++) { | |
scanf("%d",&s[i]); | |
int temp = abs(s[i]-s[i-1]); | |
if (temp<=3000) check[temp]++; | |
} | |
for (int i=1;i<N;i++) | |
if (check[i]==0) { ok = 0; break; } | |
if (ok) printf("Jolly\n"); | |
else printf("Not jolly\n"); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言