Page 19 of 30
Re: 10038 - Jolly Jumpers
Posted: Sat Apr 28, 2012 7:06 pm
by brianfry713
Sharkest yes I think normally there is a newline following the last line. Ideally your code should work either way.
Re: 10038 - Jolly Jumpers
Posted: Sat Apr 28, 2012 7:22 pm
by brianfry713
3sam 3 100 0 1 is Not jolly.
Re: 10038 - Jolly Jumpers
Posted: Sat Apr 28, 2012 10:53 pm
by 3sam
brianfry713 wrote:3sam 3 100 0 1 is Not jolly.
i can`t understand you .......what must i do to get accepted ????? plz help

Re: 10038 - Jolly Jumpers
Posted: Sun Apr 29, 2012 7:39 am
by brianfry713
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.
Re: 10038 - Jolly Jumpers
Posted: Sun May 06, 2012 10:52 pm
by Alguem
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();
}
}
}
Re: 10038 - Jolly Jumpers
Posted: Mon May 07, 2012 11:46 pm
by brianfry713
I think your RE is from a case where n=0.
Re: 10038 - Jolly Jumpers
Posted: Thu May 24, 2012 5:52 pm
by elmagnifico
"Not Jolly" is actually "Not jolly".
5 WA then AC..

10038 - Jolly Jumpers
Posted: Tue Jun 26, 2012 7:24 pm
by Mahbub9
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;
}
Re: 10038 - Jolly Jumpers
Posted: Wed Jun 27, 2012 12:01 am
by brianfry713
Why WA for 10038, help me plz..
Posted: Thu Jun 28, 2012 4:51 pm
by esharif
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;
}
Re: Why WA for 10038, help me plz..
Posted: Fri Jun 29, 2012 12:06 am
by brianfry713
Re: 10038 - Jolly Jumpers
Posted: Wed Jul 11, 2012 7:27 pm
by sumit saha shawon
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;
}
Re: 10038 - Jolly Jumpers
Posted: Tue Jul 17, 2012 1:29 am
by brianfry713
4 1 4 3 5 is Jolly
Re: 10038 - Jolly Jumpers
Posted: Thu Aug 16, 2012 6:52 pm
by S4shuvro
how can 6 3 2 4 3 2 1 be jolly? can anyone please explain?
Re: 10038 - Jolly Jumpers
Posted: Thu Aug 16, 2012 11:41 pm
by brianfry713
6 3 2 4 3 2 1 is not jolly.