Page 1 of 30

### 10038 - Jolly Jumpers

Posted: Mon May 20, 2002 11:16 pm
This fine code is not working What is the wrong wiith is ?
the [cpp] code :

#include<iostream.h>
#include<math.h>

int main()
{

long n=0;
long num[3000]={0};

while(cin >> n)
{
for(long l=0;l<n;l++)
{
cin >> num[l];
}

long v=0,vv=0,dif=0;
int fg=0;
for(long f=0;f<(n-2);f++)
{
v=labs(num[f]-num[f+1]);
vv=labs(num[f+1]-num[f+2]);
dif=labs(v-vv);
if(dif==1)fg=1;
else fg=0;
}
if(fg==1)cout << "Jolly" << endl;
else cout << "Not jolly" << endl;
n=0;num[0]=0;
}

return 0;
}

[/cpp]

Posted: Tue May 21, 2002 3:51 am
Don't see why that algorithm should work, but I think you already say "Not jolly" to a single number.

Posted: Fri Sep 27, 2002 10:07 am

I use all input data sort and check it sequentially.

So I can determine that it is Jolly or Not jolly.

But I got WA.... How to solve this problem?

Anyone who solved this problem give me some hints.

( Please post sample input data as possible as you can. )

Posted: Fri Sep 27, 2002 1:17 pm
Why do you have to sort it? You only have to check the _absolute difference_ between the current number and its pred. If it match the required condition then it's a jolly, else it's not a jolly jumper.
Be careful, i've got WA for several times too because i misunderstand the problem. I hope you don't do like i did before

### 10038 Jolly Jumpers I am confused

Posted: Mon Nov 11, 2002 12:05 pm
i'm confused with this problem.
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

what is this line meaning ? The absolute difference of succisive elements take on all the values 1 to n-1. So, if i get 3 2 1 it is a jolly jumper but if i get 1 2 3 will it be a jolly jumper or not? Here also differences cover all numbers from 1 to n-1.... i'm confused.....

thanks

Posted: Wed Nov 13, 2002 9:56 pm
It seems you mess sequence elements and their ordering numbers.
For 3 element sequence x1,x2,x3 the only requirement to be 'jolly' is:
{Abs(x1-x2), Abs(x2-x3)} in [1,2] (without repetitions).

So following number triples all are jolly:
1,2,4; 4,2,1; 104,102,101; -5,-7,-6.

Posted: Fri Nov 22, 2002 5:52 pm
Yep, they are.

### 10038, jolly jumper, max time limit exceed, help

Posted: Thu Feb 06, 2003 8:31 am
it says i used too much time, totally stuck.

[cpp]
#include <iostream.h>

int main()
{ int size, i;

int ans;
long dif;

long arr[3001];
int check [3000];

while(true)
{ ans = 0;
cin>>size;
if (size ==0)
ans = 1;

for (i=1; i<=size; i++)
cin>>arr;

for (i=1; i<=size-1; i++)
check=0;
for (i=2; i<=size && ans==0; i++)
{ dif = arr- arr[i-1];
if (dif<0) dif=-1*dif;

if (dif>size-1 || dif==0 || check[dif]!=0)
{ ans = 1;
}
else
check[dif] = 1;
}
if (ans==0)
cout<<"Jolly"<<endl;
else cout<<"Not jolly"<<endl;
}
return 0;
}

[/cpp]

Posted: Thu Feb 06, 2003 10:24 am
Don't you think you have to break that while(true) block ... ???

-turuthok-

### 10038 - Jolly Jumper WA

Posted: Thu Mar 20, 2003 9:09 am
i'm sure this is an easy problem, but however i always got WA
are there any special cases?
i've handled for a sigle integer.

[c]
/*@JUDGE_ID: XXXXX 10038 C*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX 3000

int main () {
char isjolly, selisih[MAX], dif;
long data[MAX];
int jumdata, ct;

while (1) {
if (scanf ("%d", &jumdata) != 1) break;
for (ct = 0; ct < jumdata; ct++)
scanf ("%ld", &data[ct]);
isjolly = 1;
memset (selisih, 0, sizeof (char)*MAX);
for (ct = 1; (ct < jumdata) && (isjolly); ct++) {
dif = abs (data[ct] - data[ct-1]);
if ((dif < jumdata) && (dif != 0)) {
if (selisih[dif] == 0)
selisih[dif] = 1;
else
isjolly = 0;
} else isjolly = 0;
}

if (!isjolly)
printf ("Not jolly");
else
printf ("Jolly");
printf ("\n");
}
return 0;
}
[/c]

Posted: Thu Mar 20, 2003 3:06 pm
Why you use char ? try change your variable from char to int.

Posted: Thu Mar 20, 2003 3:31 pm
why must i change the data type for variable selisih? it is only array that contains only 1 or 0, to store whether the value of difference has been used or not. if i change to int, it wil just the same, but will use more memory because int use 2 bytes (4 bytes for GCC) , and char only one byte.

Posted: Thu Mar 20, 2003 3:36 pm
But you need an integer for the variable dif.

Posted: Fri Mar 21, 2003 4:51 am
aha! how stupid i am!!!!
i didnt see such a simple thing. I got AC now.
Thank you very muchh

### 10038 Jolly Jumper

Posted: Sun Apr 06, 2003 12:15 pm
hi everyone....is there any tricky sample input/output you can give me??
i'm pretty sure that my code works fine, but always got WA.

here's my code :
[c]
#include <stdio.h>
#include <math.h>

long int p[4000];

void main(void)
{
long int i,j,k,l,N;
#ifndef ONLINE_JUDGE
freopen("10038.in","r",stdin);
freopen("10038.out","w",stdout);
#endif

while(scanf("%ld",&N)==1)
{
for (i=0;i<N;i++)
{
scanf("%ld",&p);
}
for (i=1;i<N;i++)
{
l=labs(p-p[i-1]);
if (l<1||l>=N) break;

}

if (i<N) { printf("Not jolly\n");}
else if (i==N) { printf("Jolly\n"); }

}
}

[/c]

and also some input output generated :

Code: Select all

``````4 1 4 2 3
5 1 4 2 -1 6
6 3 2 4 3 2 1
4 1 3 0 -1
4 1 3 2 -2
1 2000
2 1999 1998
3 1 2 4
3 4 2 1
3 104 102 101
3 -5 -7 -6
3 4 1 3
200 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
``````
OUTPUT :

Code: Select all

``````Jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Jolly
Jolly
Jolly
Jolly
Not jolly
Jolly

``````
Thanks for any help you can give me...i'm really stuck on this one
Nick