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
p!ter
New poster
Posts: 11
Joined: Thu Nov 18, 2004 8:55 pm

10038 - Jolly jumper WA!!

Post by p!ter »

Hi,

Can enyone tell me what is wrong with my code? plz!!!

Code: Select all

#include <stdio.h>

int t[3003];
int n;
int i,d,jolly;

int main() {
while(1==scanf("%d",&n)) {
    for(i=0; i<n; i++) scanf("%d",&t[i]);
    jolly=1;
    for(i=0; i<n-1; i++) { 
        d=t[i]-t[i+1];
        if(d<0)d=-d;
        if(d>=1 && d<=n-1) jolly=1;
        else { jolly=0; break; }
    }
    if(jolly==0) puts("Not jolly");
    else puts("Jolly");
    for(i=0; i<n+2; i++) t[i]=0; 
}
return 0;
}
THX!!
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

misunderstood..

Post by sohel »

Seems that you have misunderstood the problem.
Here is a quote from the problem statement..

Code: Select all

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
The bottom line is that the difference should consist of all the values from 1 to n-1.. but your code doesn't consider this.

Consider the input:
4 1 2 1 2
The differences are 1 1 1 ..
.. and so the output should be Not jolly, but your code seems to disagree with this. The differences should be 1 2 3 or 1 3 2 or 2 1 3 or 2 3 1 or 3 1 2 or 3 2 1 for it to be Jolly.

Hope it helps. :wink:
p!ter
New poster
Posts: 11
Joined: Thu Nov 18, 2004 8:55 pm

Post by p!ter »

Hi!!

BIG THANKS TO YOU SOHEL!!!!!
I rebuild my code and got AC!!! :D
Once again BIG THANKS!!!

Bye
Hsiang
New poster
Posts: 2
Joined: Thu Jan 20, 2005 10:29 pm

10038 - Jolly Jumpers: Time Limit Exceeded

Post by Hsiang »

Hi, I submit my code and got "Time Limit Exceeded", I' ve tried the sample inputs and some test data offered in the previous questions about Q10038.
They seems correct, but I still got "Time Limit Exceeded", Please read my code if you have free time and give me some hints about my problem. Thank you very much.

Code: Select all

// ACM Q10038: Jolly Jumpers
	
I got AC, Thank you

Last edited by Hsiang on Tue Feb 08, 2005 10:47 pm, edited 1 time in total.
mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

Post by mohiul alam prince »

hi
i have changed just
while( scanf( "%d", &length ) == 1 )
and u have got AC
Hsiang
New poster
Posts: 2
Joined: Thu Jan 20, 2005 10:29 pm

TO:mohiul alam prince

Post by Hsiang »

Thank you very much~~~~I corrected some other questions and got AC, thank you again.
sabrina
New poster
Posts: 1
Joined: Thu Sep 02, 2004 9:14 pm

10038

Post by sabrina »

Hi, I have a problem with 10038 - I keep getting a WA. Anyone there that can look through it and tell me what could possibly be wrong with it, pleaaase...

-----------------------------------------------------------------------------------
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;

import java.util.StringTokenizer;

interface MyReader {
String readLine () throws IOException;}

final class MyBufferedReader implements MyReader {
private InputStream in;

public MyBufferedReader (InputStream in) {
this.in = in;}

public String readLine () throws IOException {
final StringBuffer s = new StringBuffer(255);
int i = 0;
while (((i = in.read()) != '\n') && (i != -1))
if (i != '\r')
s.append((char) i);
if (i == -1)
return null;
return s.toString();}}

final class Main {
public static String eval (int[] valuesToEval)
{
int calculate = valuesToEval.length - 1; //n-1, is the same as size of array since indexes range from 0 -> n
for (int i = 0; i < valuesToEval.length; i++)
{
if ((valuesToEval - valuesToEval[i+1]) == abs(calculate))
{
calculate--;
return "Jolly";
}//end if
}//end for
return "Not jolly";
}//end eval

//helper method - calculating absolute value
public static int abs (int x)
{
if (x >= 0)
return x;
else // (x < 0)
return -x;
}//end helper method

public static void main (String[] args) {
try {
MyReader in = new MyBufferedReader(System.in);
/*
MyReader in = new MyBufferedReader(new FileInputStream("main.in"));
*/
String s;
while ((s = in.readLine()) != null) {
StringTokenizer st = new StringTokenizer(s);
int cases = Integer.parseInt(st.nextToken());
int[] valuesToEval = new int[cases];
for (int i = 0; i < valuesToEval.length; i++)
{
int j = Integer.parseInt(st.nextToken());
}//end for
String s2 = eval(valuesToEval);
System.out.println(s2);}}
catch (IOException e) {
e.printStackTrace();}}
}//end class main
-----------------------------------------------------------------------------------
sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

10038 WA

Post by sunnycare »

why it is always WA............

I misunderstand the problem??

Code: Select all

#include <iostream>

using namespace std;

void main()
{
	unsigned long n;
	while((cin>>n) != NULL)
	{
		if(n!=1)
		{
			long *p=new long[n];

			long *q=new long[n];
			unsigned long i=0;
			while(i<n)
			{
				cin>>p[i];
				q[i]=0;
				i++;
			}
			for(i=0;i<n-1;i++)
			{
				unsigned long tmp;
				if(p[i]<p[i+1])
					tmp=p[i+1]-p[i];
				else
					tmp=p[i]-p[i+1];
				if(tmp>n-1|| tmp==0)
				{
					cout<<"Not jolly\n";
					break;
				}
				if(q[tmp]!=0)
				{
					cout<<"Not jolly\n";
					break;
				}
				
			}
			if(i==n-1)
				cout<<"Jolly\n";
		}
		else
		{
			cout<<"Jolly\n";
		}
	}
}

[/code]
mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

Post by mohiul alam prince »

Hi
Ur programm gives this output for this input

Code: Select all

5 3 4 2 3 5
Jolly
but will be "Not jolly"

thanks:)
MAP
sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

Post by sunnycare »

thanks

accepted!
nebel
New poster
Posts: 4
Joined: Sun Apr 10, 2005 3:19 pm
Location: Kiev, Ukraine
Contact:

10038

Post by nebel »

sorry, because of troubling you, but

Type Vector = array [1..3000]of LONGINT;
var n : integer;
Inp,Stt : Vector;
min,max :longint;
i :integer;
flag : boolean;
jolly : Vector;
jc : integer;
begin
jc :=0;
for i := 1 to 3000 do
begin
jolly :=0;
inp :=0;
stt :=0;
end;

while not eof (input) do
begin
read (input,n);
min := 2000000000;
max := -2000000000;
for i := 1 to 3000 do Stt := 0;
for i:=1 to n do
begin
read (input,Inp);
if max<Inp then max := Inp;
if min>Inp then min := Inp;
end;
if max - min <> N-1 Then
Writeln ('Not jolly')
else
begin
for i:=1 to n do
Stt[ Inp - min + 1 ] := 1 ;
flag := true;
for i :=1 to n-1 do
if Stt[i] = 0 then
begin
flag := false;
break;
end;
if flag then
Writeln ('Jolly')
else
Writeln ('Not jolly')
end;
end;
end.

As for me this code works correktly, may be any problem with inputing data ?
thanks in advance
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

logical mistake

Post by Sedefcho »

I think you have one or more logical mistakes.

You check if

Code: Select all

 max - min <> N-1 
If that condition is true you
just print "Not jolly". That is wrong.

You need to consider differences only between consecutive
members of the input sequence.

Maybe you have other logical erorrs too. I've just
noticed this one from first sight.

With that program are you able to
match even the sample I/O ?!
nebel
New poster
Posts: 4
Joined: Sun Apr 10, 2005 3:19 pm
Location: Kiev, Ukraine
Contact:

Post by nebel »

Sedefcho thank's for your answer, i know that reading somobodies code is ungrateful work.
but i can't agree with your observation. As it mentioned in the problem differences take all the values through 1 to N-1, so if the condition
(min - max <> N-1) isn't true the input demands will never carry Out !
may be I'm wrong again. If it's not so difficult send plese some simple tests with answers (of comments).
thanks in advanve
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho »

Nebel,

What does your program print for this test case

Code: Select all

4 -1 -2 0 3
The right answer is

Code: Select all

Jolly
The difference between minElement and maxElement
is 5 as you can see. Do you see what I meant in
my previous post ?
You need to inspect only differences between
consecutive numbers.

If the difference between the min and the max is not N-1
you can't make any conclusion based on that fact.


Regards.
nebel
New poster
Posts: 4
Joined: Sun Apr 10, 2005 3:19 pm
Location: Kiev, Ukraine
Contact:

Post by nebel »

great thanks,
i didnt pay attention to this condition :(
sorry me for troubled you :D
Post Reply

Return to “Volume 100 (10000-10099)”