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

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

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Sat Apr 28, 2012 7:06 pm

Sharkest yes I think normally there is a newline following the last line. Ideally your code should work either way.
Check input and AC output for thousands of problems on uDebug!

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

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Sat Apr 28, 2012 7:22 pm

3sam 3 100 0 1 is Not jolly.
Check input and AC output for thousands of problems on uDebug!

3sam
New poster
Posts: 6
Joined: Mon Apr 09, 2012 8:33 pm

Re: 10038 - Jolly Jumpers

Post by 3sam » Sat Apr 28, 2012 10:53 pm

brianfry713 wrote:3sam 3 100 0 1 is Not jolly.
i can`t understand you .......what must i do to get accepted ????? plz help :)

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

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Sun Apr 29, 2012 7:39 am

Your code fails on the input I posted. Your algorithm is wrong. Read the problem again. 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. So you need to make sure your diff array contains all of those values. Right now you only check each one to see if it equals y or if it equals one of the next two.

Alguem
New poster
Posts: 1
Joined: Sun May 06, 2012 10:47 pm

Re: 10038 - Jolly Jumpers

Post by Alguem » Sun May 06, 2012 10:52 pm

I think my program is correct and I can't find what's wrong. Please help me

import java.io.*;
import java.util.*;


class JollyJumper {


public static void main(String[] args) {
JollyJumper myWork = new JollyJumper();
myWork.begin();
}

void jollyFunction(Set S,long n)
{
long i;

for(i=1;i<n;i++)
if(!S.contains(i))
{
System.out.println("Not jolly");
return;
}

System.out.println("Jolly");
}

void begin () {
String line;
long a,b,i,n;
Set S = new HashSet();
try{

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

while( true )
{
line=in.readLine();
if(line==null)
break;

Scanner ins = new Scanner(line);

if(!ins.hasNextLong())
break;

n=ins.nextLong();

a=ins.nextLong();

for(i=2;i<=n;i++)
{
b=ins.nextLong();

S.add(Math.abs(b-a));
a=b;
}

jollyFunction(S,n);
S.clear();
}

}

catch(Exception e)
{
e.printStackTrace();
}
}

}

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

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Mon May 07, 2012 11:46 pm

I think your RE is from a case where n=0.
Check input and AC output for thousands of problems on uDebug!

elmagnifico
New poster
Posts: 5
Joined: Mon Apr 30, 2012 10:15 am

Re: 10038 - Jolly Jumpers

Post by elmagnifico » Thu May 24, 2012 5:52 pm

Code: Select all

code removed after AC
"Not Jolly" is actually "Not jolly".
5 WA then AC.. :-?

Mahbub9
New poster
Posts: 1
Joined: Tue Jun 26, 2012 7:16 pm

10038 - Jolly Jumpers

Post by Mahbub9 » Tue Jun 26, 2012 7:24 pm

What's wrong with this code? I didn't find anything wrong. But I'm getting WA. Anyone please help me.



#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,jolly[3020],absolute_value,c,i;
while(scanf("%d",&n)==1)
{
c=1;
for(i=1;i<=n;i++)

scanf("%d",&jolly);
for(i=n;i>=2;i--)
{
if(abs(jolly-jolly[i-1])!=c)
{
printf("Not jolly\n");
break;
}
else c+=1;
}

if(c==n)
printf("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 » Wed Jun 27, 2012 12:01 am

Try the I/O posted in this thread: http://acm.uva.es/board/viewtopic.php?t=16018
Check input and AC output for thousands of problems on uDebug!

esharif
New poster
Posts: 18
Joined: Sun Jun 03, 2012 11:56 pm

Why WA for 10038, help me plz..

Post by esharif » Thu Jun 28, 2012 4:51 pm

Code: Select all

#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<stdio.h>
#include<stdlib.h>
#define N 3001

using namespace std;

long int a[N];

int main()
{
	long int n, i, j, l, temp, dif, num, flag;
	while(scanf("%ld",&n)==1)
	{
	    flag=0;
	    l=0;
        for(i=0;i<n;i++)
	    {
	        scanf("%ld", &num);
            if(i!=0)
            {
                dif=abs(num-temp);
                a[i-1]=dif;
            }
            temp=num;
	    }

	    if(n==1)
            printf("Jolly\n");
        else if(n==2)
	    {
	        temp=abs(a[0]-a[1]);
	        printf("temp is %ld \n", temp);
	        if(temp==0 || temp==1)
                printf("Jolly\n");
            else
                printf("Not jolly\n");
	    }
        else if(n>2)
	    {
	        if(a[1]>a[0])
                for(i=0;i<n-2;i++)
                {
                    if(a[i+1]==a[i]+1)
                        l++;
                }
            else if(a[1]<a[0])
                for(i=0;i<n-2;i++)
                {
                    if(a[i]==a[i+1]+1)
                        l++;
                }
            if(l!=n-2)
                printf("Not jolly\n");
            else if(l==n-2)
                printf("Jolly\n");
	    }
    }
	return 0;
}

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

Re: Why WA for 10038, help me plz..

Post by brianfry713 » Fri Jun 29, 2012 12:06 am

Try the I/O posted in this thread: http://acm.uva.es/board/viewtopic.php?t=16018
Check input and AC output for thousands of problems on uDebug!

sumit saha shawon
New poster
Posts: 19
Joined: Tue Jun 26, 2012 9:19 pm

Re: 10038 - Jolly Jumpers

Post by sumit saha shawon » Wed Jul 11, 2012 7:27 pm

what is wrong with my algorithm:
#include<stdio.h>
#include<math.h>
int a[3050],k[3050];
int main()
{
int n,i,l,dif,y,j,temp;
while(scanf("%d",&n)==1)
{
y=0;
j=0;
// scanf("%d",&a[0]);
for(i=0;i<n;i++)
scanf("%d",&a);
for(i=0;i<n-1;i++)
{
temp=(a-a[i+1]);
if(temp<0)
temp=temp*(-1);
k[j]=temp;
j++;

}
for(i=0;i<j-1;i++)
{
dif=(k-k[i+1]);
if(dif<0)
dif=dif*(-1);
if(dif!=1)
{
y=1;
break;
}
}
if(y==1)
printf("Not jolly\n");
else
printf("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 » Tue Jul 17, 2012 1:29 am

4 1 4 3 5 is Jolly
Check input and AC output for thousands of problems on uDebug!

S4shuvro
New poster
Posts: 1
Joined: Mon Aug 13, 2012 1:10 pm

Re: 10038 - Jolly Jumpers

Post by S4shuvro » Thu Aug 16, 2012 6:52 pm

how can 6 3 2 4 3 2 1 be jolly? can anyone please explain?

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

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Thu Aug 16, 2012 11:41 pm

6 3 2 4 3 2 1 is not jolly.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 100 (10000-10099)”