10038 - Jolly Jumpers
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
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!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
3sam 3 100 0 1 is Not jolly.
Check input and AC output for thousands of problems on uDebug!
Re: 10038 - Jolly Jumpers
i can`t understand you .......what must i do to get accepted ????? plz helpbrianfry713 wrote:3sam 3 100 0 1 is Not jolly.

-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
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
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();
}
}
}
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();
}
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
I think your RE is from a case where n=0.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 5
- Joined: Mon Apr 30, 2012 10:15 am
10038 - Jolly Jumpers
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;
}
#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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
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!
Why WA for 10038, help me plz..
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: Why WA for 10038, help me plz..
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!
-
- New poster
- Posts: 19
- Joined: Tue Jun 26, 2012 9:19 pm
Re: 10038 - Jolly Jumpers
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;
}
#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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
4 1 4 3 5 is Jolly
Check input and AC output for thousands of problems on uDebug!
Re: 10038 - Jolly Jumpers
how can 6 3 2 4 3 2 1 be jolly? can anyone please explain?
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
6 3 2 4 3 2 1 is not jolly.
Check input and AC output for thousands of problems on uDebug!