Page 7 of 30

10038 - Jolly jumper WA!!

Posted: Fri Jan 14, 2005 7:26 pm
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!!

misunderstood..

Posted: Sat Jan 15, 2005 7:35 am
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:

Posted: Sat Jan 15, 2005 12:31 pm
by p!ter
Hi!!

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

Bye

10038 - Jolly Jumpers: Time Limit Exceeded

Posted: Tue Feb 01, 2005 1:17 am
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


Posted: Tue Feb 01, 2005 12:37 pm
by mohiul alam prince
hi
i have changed just
while( scanf( "%d", &length ) == 1 )
and u have got AC

TO:mohiul alam prince

Posted: Tue Feb 01, 2005 5:51 pm
by Hsiang
Thank you very much~~~~I corrected some other questions and got AC, thank you again.

10038

Posted: Wed Feb 09, 2005 10:18 pm
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
-----------------------------------------------------------------------------------

10038 WA

Posted: Mon Mar 21, 2005 4:59 am
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]

Posted: Tue Mar 22, 2005 2:44 pm
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

Posted: Fri Apr 01, 2005 2:11 am
by sunnycare
thanks

accepted!

10038

Posted: Sun Apr 10, 2005 3:23 pm
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

logical mistake

Posted: Mon Apr 11, 2005 3:32 pm
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 ?!

Posted: Wed Apr 13, 2005 5:59 am
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

Posted: Wed Apr 13, 2005 4:56 pm
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.

Posted: Sat Apr 16, 2005 1:00 am
by nebel
great thanks,
i didnt pay attention to this condition :(
sorry me for troubled you :D