10038 - Jolly Jumpers

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:

10038 - Jolly Jumpers

Post by Moni »

This fine code is not working :cry: What is the wrong wiith is ? :roll:
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]
Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann »

Don't see why that algorithm should work, but I think you already say "Not jolly" to a single number.
soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

Post by soyoja »

I still don't know about this problem.

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. )
arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

Post by arc16 »

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 :)
rakeb
New poster
Posts: 42
Joined: Fri Aug 30, 2002 2:51 pm
Location: France

10038 Jolly Jumpers I am confused

Post by rakeb »

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
SMBfromRU
New poster
Posts: 7
Joined: Wed Sep 11, 2002 9:19 am

Post by SMBfromRU »

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.
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

Yep, they are.
Eric____
New poster
Posts: 8
Joined: Thu Jan 30, 2003 10:13 am

10038, jolly jumper, max time limit exceed, help

Post by Eric____ »

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]
turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok »

Don't you think you have to break that while(true) block ... ???

-turuthok-
anak_papua
New poster
Posts: 7
Joined: Wed Mar 19, 2003 3:16 pm

10038 - Jolly Jumper WA

Post by anak_papua »

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]
Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

Why you use char ? try change your variable from char to int. :wink:
anak_papua
New poster
Posts: 7
Joined: Wed Mar 19, 2003 3:16 pm

Post by anak_papua »

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.
Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

But you need an integer for the variable dif.
anak_papua
New poster
Posts: 7
Joined: Wed Mar 19, 2003 3:16 pm

Post by anak_papua »

aha! how stupid i am!!!!
i didnt see such a simple thing. I got AC now.
Thank you very muchh :) :) :) :) :)
Nick
Learning poster
Posts: 53
Joined: Sun Jan 12, 2003 4:49 am

10038 Jolly Jumper

Post by Nick »

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
Post Reply

Return to “Volume 100 (10000-10099)”