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

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

Re: 10038 - Jolly Jumpers

Post by shondhi » Sat Oct 13, 2012 3:23 pm

Thank you for your reply.
That was not my problem. My actual problem is:
For my 1st input: 4 1 4 2 3 the output screen show me that it is Jolly and for the 2nd input: 5 1 4 2 -1 6 the output screen show me that it is Not jolly. Both two test inputs are ok. But my problem occurs from the 3rd test case. For my 3rd input: 4 1 4 2 3 the output screen show me that it is Not jolly but it is a Jolly. What is the problem? Why the error occur?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Tue Oct 16, 2012 1:26 am

On line 18 you set up to c[n-1], but on line 22 you check up to c[n], so that's why you see a difference. Also your algorithm won't work for a case like: 3 1 2 4, output should be Jolly.
Check input and AC output for thousands of problems on uDebug!

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

Re: 10038 - Jolly Jumpers

Post by shondhi » Tue Oct 16, 2012 10:39 am

Thank you for your reply. I just need to check my code.

Hilda_Chen
New poster
Posts: 1
Joined: Wed Oct 24, 2012 10:28 am

Re: 10038 - Jolly Jumpers

Post by Hilda_Chen » Wed Oct 24, 2012 10:36 am

This main problem is that the absolute values may not be order. for example, 1,2,3 is ok, 2, 3,1 is ok,too.

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

Re: 10038 - Jolly Jumpers

Post by shondhi » Thu Nov 01, 2012 8:03 am

Can anyone provide me some sample input and sample output of Jolly Jumpers?

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

Re: 10038 - Jolly Jumpers

Post by shondhi » Thu Nov 01, 2012 8:13 pm

What's wrong in my code? Got WA!!

Code: Select all

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
    int n, i, count, j;
    int a[3002], c[3002];
    while(cin>>n)
    {
        for(i = 1; i <= n; i++)
        {
            cin>>a[i];
        }
        for(i = 1; i <= n-1; i++)
        {
            c[i] = abs(a[i] - a[i+1]);
        }
       for(i = 1; i <= n-1; i++)
        {
            for(j = i + 1; j <= n-1; j++)
            {
                count = 0;
                if(abs(c[i] - c[j]) == 1)
                {
                    count = 1;
                }
            }
        }
        if(count == 1)
        {
            printf("%s\n", "Jolly");
        }
        else
        {
            printf("%s\n", "Not jolly");
        }
    }
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Fri Nov 02, 2012 12:14 am

3 1 3 6 is Not jolly
Check input and AC output for thousands of problems on uDebug!

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

Re: 10038 - Jolly Jumpers

Post by shondhi » Fri Nov 02, 2012 7:28 am

Can anyone tell me what's wrong now? Still got WA!!!! :(

Code: Select all

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
    int n, i, count, j;
    int a[3002], c[3002];
    while(cin>>n)
    {
        for(i = 1; i <= n; i++)
        {
            cin>>a[i];
        }
        for(i = 1; i <= n-1; i++)
        {
            c[i] = abs(a[i] - a[i+1]);
        }
       for(i = 1; i <= n-1; i++)
        {
            for(j = i + 1; j <= n-1; j++)
            {
                count = 0;
                if(c[1] == 1 || c[n-1] == 1)
                {
                    if(abs(c[i] - c[j]) == 1)
                    {
                        count = 1;
                    }
                }
                else
                {
                    count = 0;
                }
            }
        }
        if(count == 1)
        {
            printf("%s\n", "Jolly");
        }
        else
        {
            printf("%s\n", "Not jolly");
        }
    }
return 0;
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Fri Nov 02, 2012 10:44 pm

5 1 4 1 3 2 is Not jolly.
See http://acm.uva.es/board/viewtopic.php?t=16018
Check input and AC output for thousands of problems on uDebug!

ivsv
New poster
Posts: 1
Joined: Sat Oct 27, 2012 6:12 am

Re: 10038 - Jolly Jumpers

Post by ivsv » Sun Nov 04, 2012 4:32 am

I struggled A LOT with this problem.

The problem specification is misleading.
The problem reads:
"Each line of input contains an integer n < 3, 000 followed by n integers representing the sequence."

But there are test cases where n == 3000.
No wonder why the authors said "use arrays larger than what you really need". I thought this was because they assumed we were sloppy coders. I didn't have in mind THEY could be sloppy as well.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Tue Nov 06, 2012 1:59 am

The problem statement has n<=3000
Check input and AC output for thousands of problems on uDebug!

wawando
New poster
Posts: 1
Joined: Mon Nov 26, 2012 6:44 pm

Re: 10038 - Jolly Jumpers

Post by wawando » Mon Nov 26, 2012 6:54 pm

hello, I need some help here, I dunno where's the mistake of my code, i keep getting WA.
pls help :)

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

using namespace std;

int main()
{
long long arr[3001];
int n;
while(scanf("%d",&n)!=EOF)
{
bool jolly=true;
bool used[3001];
for(int i=0;i<n;i++)
{
used=false;
}

for(int i=0;i<n;i++)
{
scanf("%lld",&arr);
if(i>0)
{
long long diff=abs(arr-arr[i-1]);
if (diff<n) used[diff]=true;
}
}

if(n<=1) printf("Not jolly\n");
else
{
for(int i=1;i<n;i++) if(not used) jolly=false;

if(jolly) printf("Jolly\n");
else printf("Not jolly\n");
}
}

return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Fri Nov 30, 2012 6:41 am

input:
1 1
AC output:
Jolly
Check input and AC output for thousands of problems on uDebug!

raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

Re: 10038 - Jolly Jumpers

Post by raj » Sat Feb 16, 2013 6:11 pm

CAN ANYONE PLEASE TELL ME WHERE IS THE PROBLEM???
ONLINE JUDGE SAYS ITS WRONG ANSWER.............. :(


import java.io.*;
import java.util.*;
public class Main{
public static void main(String [] args){
Scanner k = new Scanner(System.in);
while(true)
{
String s = k.nextLine();
int space = 0,c = 0;
for(c = 0;c<s.length();c++)
{
if(s.charAt(c)==' ')
{
space++;
}
}
Scanner b = new Scanner(s);
int [] v = new int [s.length()-space];
c = 0;
while(b.hasNextInt())
{
int i = b.nextInt();
v[c] = i;
c++;
}
int p = 1,chq = 0,save = 0,save1 = 0;
for(int t =0;t<v.length;t++)
{
if(!(v[t]>0))
{
chq = 1;
break;
}
}
while(p<v.length)
{
int max=0,min=0;
if(v[p-1]>v[p])
{
max = v[p-1];
min = v[p];
}
else
{
max = v[p];
min = v[p-1];
}
if(p==1)
{
save = max - min;
p++;
}
else
{
save1 = save;
save = max - min;
if((save==save1)||(save == (save1-1)))
{
p++;
}
else
{
chq = 1;
break;
}
}
}
if(chq == 0)
{
System.out.println("Jolly");
}
else
{
System.out.println("Not jolly");
}
}
}
}

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 10038 - Jolly Jumpers

Post by lbv » Sat Feb 16, 2013 10:08 pm

raj wrote:CAN ANYONE PLEASE TELL ME WHERE IS THE PROBLEM???
ONLINE JUDGE SAYS ITS WRONG ANSWER.............. :(
Was the verdict "Wrong Answer" or "Runtime Error"?

For now, I can see that your code throws a java.util.NoSuchElementException exception when it reaches the end of the input. Try changing this:

Code: Select all

        while(true)
        {
            String s = k.nextLine();
            // etc.
        }
with something like:

Code: Select all

        while(k.hasNextLine())
        {
            String s = k.nextLine();
            // etc.
        }

Post Reply

Return to “Volume 100 (10000-10099)”