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

10599
New poster
Posts: 3
Joined: Sat Nov 19, 2005 11:24 am

Post by 10599 »

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
int main()
{long int n,a[3000],b[3000],c[3000],d[3000],e,i,k,t,x;
#ifndef ONLINE_JUDGE
close (0); open ("myprog.in", O_RDONLY);
close (1); open ("myprog.out1", O_WRONLY | O_CREAT, 0600);
#endif
while( scanf("%ld",&n)==1){
for(i=0;i<n;i++)
{scanf("%ld",&a);}
for(k=0,t=1;k<(n-1);k++,t++)
{b[k]=t;d[k]=0;}
for(i=0;i<(n-1);i++)
{c=a[i+1]-a;
if(c<0)
c=-c;

for(k=0;k<(n-1);k++)
{for(e=0;e<(n-1);e++)
{if(c[k]==b[e])
d[e]++;}
}
}
for(k=0;k<(n-1);k++)
{if(d[k]==0)
{printf("Not jolly\n");
x=0;
goto end;}
else
x=1;
}
end:
if(x==1&&d[n-1]==0)
printf("Jolly\n");

}






return 0;
}


while( scanf("%ld",&n)==1)
OR
while( scanf("%ld",&n)!=EOF)
TLE
>"<
tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Post by tan_Yui »

Hi.
You have no need to write :
#ifndef ONLINE_JUDGE
close (0); open ("myprog.in", O_RDONLY);
close (1); open ("myprog.out1", O_WRONLY | O_CREAT, 0600);
#endif
Following is one of the example which is implemented.
This code tries to read the lines till EOF.
(Of course, the original code is yours. I changed some parts. )

Code: Select all

#include <stdio.h>

int main() {
  long int n,a[3000],b[3000],c[3000],d[3000],e,i,k,t,x;
  while(scanf("%ld",&n)!=EOF) {
    for(i=0;i<n;i++) {scanf("%ld",&a[i]);}
    for(k=0,t=1;k<(n-1);k++,t++) {
      b[k]=t;d[k]=0;
    }
    for(i=0;i<(n-1);i++) {
      c[i]=a[i+1]-a[i];
      if(c[i]<0) c[i]=-c[i];
      
      for(k=0;k<(n-1);k++) {
        for(e=0;e<(n-1);e++) {
          if(c[k]==b[e]) d[e]++;
        }
      }
    }
    for(k=0;k<(n-1);k++) {
      if(d[k]==0) {
        printf("Not jolly\n");
        x=0;
        goto end;
      } 
      else
        x=1;
    } 
  end: 
    if(x==1&&d[n-1]==0) printf("Jolly\n");
  }
  return 0;
}
By the way, you'll failed for some inputs.
-> http://online-judge.uva.es/board/viewto ... ight=10038
And, there have already been many threads in this board.
You can search by using the word "10038".
This will help you for your coding.

Best regards.
liii
New poster
Posts: 1
Joined: Sun Nov 27, 2005 3:26 pm

10038 jolly jumpur

Post by liii »

I am getting wrong answer.Where is problem? plz help me.

Code: Select all

#include<stdio.h>
#include<iostream.h>
//#include<algorithum.h>

int main()
{           long int n,a[4000],s=0,jo=1,p=0;
  while(cin>>n)
  {
			//if(n==0)
			//break;

	for(long int i=0;i<n;i++)
	{
	  cin>>a[i];
	}
	//cout<<a[5];
	for(long int j=1;j<n;j++)
	{     //p=0;
		if(a[j-1]<a[j])
		{   s=0;
			for(int t=a[j-1];t<a[j];t++)
			{s++;}
			if(s<4)
			  jo*=1;
			else
				jo*=0;
			//p=1;
			//jo*=p;

		}

		if(a[j-1]>a[j])
		{   s=0;
			for(int y=a[j];y<a[j-1];y++)
			{s++;}
			if(s<4)
			  jo*=1;
			else
				jo*=0;
			//p=1;

		}
	}
		if(jo==1 && p==1)
		  cout<<"Jolly"<<endl;
		if(jo==0)
		   cout<<"Not jolly"<<endl;
	

   }
  return 0;
}
Tanu
Learning poster
Posts: 70
Joined: Sun May 29, 2005 12:46 pm
Location: Mars

Post by Tanu »

I tried to check Ur code but it is not giving answer even for the sample input output... check it again...
Try...
Roby
Experienced poster
Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia
Contact:

Post by Roby »

And here some input for you test (after you fix your program bug (posting above)):

Code: Select all

4 1 4 2 3
5 1 4 2 -1 6
4 1 4 3 5
And here's the correct output:

Code: Select all

Jolly
Not jolly
Jolly
Hope it helps :wink:
njc
New poster
Posts: 2
Joined: Wed Jan 25, 2006 7:53 pm

progamming challenges website

Post by njc »

i've been trying the website for the progamming challenges book (on the front page of the online-judge site)
i'm having trouble submitting my code. it seems to work properly and give correct output, but everything i try submitting i get a wrong answer reply.
for example:

this problem: http://www.programming-challenges.com/p ... ormat=html

here is my code:

Code: Select all


*fixed*
it seems to work, but i get a wrong answer when submitting. this isn't the only one either.

does that site use this online judge or a different one? any help would be great. thanks.
Last edited by njc on Thu Jan 26, 2006 5:13 pm, edited 1 time in total.
chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

Please check your code carefully before posting. Obviously there is something wrong with your code. Which is why the judge at programming challenges website says WA. By the way, I believe the problem you are referrig to in your code is problem 10038 Jolly Jumpers of this judge. You could have tried searching for threads related to problems 10038 here.

Also, try this input:

Code: Select all

1 1
4 1 4 2 3
Your code prints

Code: Select all

JollyJolly
You forgot to print a newline ('\n') after each line of output. Now remove this code after you get AC.
njc
New poster
Posts: 2
Joined: Wed Jan 25, 2006 7:53 pm

Post by njc »

thanks for the help. i wasn't aware that this judge had any of the same problems. and the compiler/ide i'm using automatically put the output on a new line for some reason, which is why i didn't understand how i was getting a WA.
devious
New poster
Posts: 13
Joined: Wed Feb 22, 2006 1:26 am

Post by devious »

two years later, and some one randomly decides to answer your question. You are only reading the first 255 characters on a line. There can be up to 2999 different numbers, all of which can be up to 4 characters long, and not to mention the spaces in between the numbers. 255? I don't think so lol
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

Well, the thing is that he is using the "default" readLine() (as in official example of a Java submission).

I bet he figured out the pitfalls of such approach in the meantime :)

(It probably meant switching to C/C++)

Darko
chenyen
New poster
Posts: 1
Joined: Mon Mar 13, 2006 6:16 pm

10038 WHY CE

Post by chenyen »

it can run on my computer but ...online-judge give me Complie ERROR :evil:

Code: Select all

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int n=0,i=0,j[3000]={0};
	bool isj=true;
	while(1)
	{
		cin >> n;
		if(cin.fail()) break;
		for(i=0;i<n;i++)
		{
			cin >> j[i];
		}
		isj=true;
		for(i=0;i<(n-1);i++)
		{
			if((abs((j[i+1]-j[i]))<1)||(abs((j[i+1]-j[i]))>(n-1)))
			{
				isj=false;
				cout << "Not jolly" << endl;
				break;
			}
		}
		if(isj==true)
			cout << "Jolly" << endl;		

	}
	return 0;
}
fayyazkl
New poster
Posts: 11
Joined: Thu Mar 16, 2006 8:02 am
Location: Lahore, Pakistan

Post by fayyazkl »

I dont think bool data type is part of C++ ANSI standard. You might be using Visual Studio or something which works but this wont
There are 10 types of people. Those who can read binary and those who cant ;)
http://acm.uva.es/problemset/usersjudge.php?user=37504
chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

bool will compile in this online judge.

However, the compile error lies in the use of the abs function. I suggest you explicitly cast the expression you pass to the abs function to a double, and then you cast the value returned from abs back to int. Alternatively, as a workaround, #include math.h instead of cmath.
fpavetic
Learning poster
Posts: 51
Joined: Sat Mar 04, 2006 8:00 pm

Post by fpavetic »

However, the compile error lies in the use of the abs function. I suggest you explicitly cast the expression you pass to the abs function to a double, and then you cast the value returned from abs back to int. Alternatively, as a workaround, #include math.h instead of cmath.
int abs() is declared in stdlib.h or cstdlib.
chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

int abs() is declared in stdlib.h or cstdlib.
My mistake :oops:

In newer versions of gcc it seems that cmath header included the int abs function as well.
Post Reply

Return to “Volume 100 (10000-10099)”