Page 21 of 30
Re: 10038 - Jolly Jumpers
Posted: Sat Oct 13, 2012 3:23 pm
by shondhi
Thank you for your reply.
That was not my problem. My actual problem is:
For my 1st input: 4 1 4 2 3 the output screen show me that it is Jolly and for the 2nd input: 5 1 4 2 -1 6 the output screen show me that it is Not jolly. Both two test inputs are ok. But my problem occurs from the 3rd test case. For my 3rd input: 4 1 4 2 3 the output screen show me that it is Not jolly but it is a Jolly. What is the problem? Why the error occur?
Re: 10038 - Jolly Jumpers
Posted: Tue Oct 16, 2012 1:26 am
by brianfry713
On line 18 you set up to c[n-1], but on line 22 you check up to c[n], so that's why you see a difference. Also your algorithm won't work for a case like: 3 1 2 4, output should be Jolly.
Re: 10038 - Jolly Jumpers
Posted: Tue Oct 16, 2012 10:39 am
by shondhi
Thank you for your reply. I just need to check my code.
Re: 10038 - Jolly Jumpers
Posted: Wed Oct 24, 2012 10:36 am
by Hilda_Chen
This main problem is that the absolute values may not be order. for example, 1,2,3 is ok, 2, 3,1 is ok,too.
Re: 10038 - Jolly Jumpers
Posted: Thu Nov 01, 2012 8:03 am
by shondhi
Can anyone provide me some sample input and sample output of Jolly Jumpers?
Re: 10038 - Jolly Jumpers
Posted: Thu Nov 01, 2012 8:13 pm
by shondhi
What's wrong in my code? Got WA!!
Code: Select all
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
int n, i, count, j;
int a[3002], c[3002];
while(cin>>n)
{
for(i = 1; i <= n; i++)
{
cin>>a[i];
}
for(i = 1; i <= n-1; i++)
{
c[i] = abs(a[i] - a[i+1]);
}
for(i = 1; i <= n-1; i++)
{
for(j = i + 1; j <= n-1; j++)
{
count = 0;
if(abs(c[i] - c[j]) == 1)
{
count = 1;
}
}
}
if(count == 1)
{
printf("%s\n", "Jolly");
}
else
{
printf("%s\n", "Not jolly");
}
}
return 0;
}
Re: 10038 - Jolly Jumpers
Posted: Fri Nov 02, 2012 12:14 am
by brianfry713
3 1 3 6 is Not jolly
Re: 10038 - Jolly Jumpers
Posted: Fri Nov 02, 2012 7:28 am
by shondhi
Can anyone tell me what's wrong now? Still got WA!!!!
Code: Select all
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
int n, i, count, j;
int a[3002], c[3002];
while(cin>>n)
{
for(i = 1; i <= n; i++)
{
cin>>a[i];
}
for(i = 1; i <= n-1; i++)
{
c[i] = abs(a[i] - a[i+1]);
}
for(i = 1; i <= n-1; i++)
{
for(j = i + 1; j <= n-1; j++)
{
count = 0;
if(c[1] == 1 || c[n-1] == 1)
{
if(abs(c[i] - c[j]) == 1)
{
count = 1;
}
}
else
{
count = 0;
}
}
}
if(count == 1)
{
printf("%s\n", "Jolly");
}
else
{
printf("%s\n", "Not jolly");
}
}
return 0;
}
Re: 10038 - Jolly Jumpers
Posted: Fri Nov 02, 2012 10:44 pm
by brianfry713
Re: 10038 - Jolly Jumpers
Posted: Sun Nov 04, 2012 4:32 am
by ivsv
I struggled A LOT with this problem.
The problem specification is misleading.
The problem reads:
"Each line of input contains an integer n < 3, 000 followed by n integers representing the sequence."
But there are test cases where n == 3000.
No wonder why the authors said "use arrays larger than what you really need". I thought this was because they assumed we were sloppy coders. I didn't have in mind THEY could be sloppy as well.
Re: 10038 - Jolly Jumpers
Posted: Tue Nov 06, 2012 1:59 am
by brianfry713
The problem statement has n<=3000
Re: 10038 - Jolly Jumpers
Posted: Mon Nov 26, 2012 6:54 pm
by wawando
hello, I need some help here, I dunno where's the mistake of my code, i keep getting WA.
pls help
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long long arr[3001];
int n;
while(scanf("%d",&n)!=EOF)
{
bool jolly=true;
bool used[3001];
for(int i=0;i<n;i++)
{
used
=false;
}
for(int i=0;i<n;i++)
{
scanf("%lld",&arr);
if(i>0)
{
long long diff=abs(arr-arr[i-1]);
if (diff<n) used[diff]=true;
}
}
if(n<=1) printf("Not jolly\n");
else
{
for(int i=1;i<n;i++) if(not used) jolly=false;
if(jolly) printf("Jolly\n");
else printf("Not jolly\n");
}
}
return 0;
}
Re: 10038 - Jolly Jumpers
Posted: Fri Nov 30, 2012 6:41 am
by brianfry713
input:
1 1
AC output:
Jolly
Re: 10038 - Jolly Jumpers
Posted: Sat Feb 16, 2013 6:11 pm
by raj
CAN ANYONE PLEASE TELL ME WHERE IS THE PROBLEM???
ONLINE JUDGE SAYS ITS WRONG ANSWER..............
import java.io.*;
import java.util.*;
public class Main{
public static void main(String [] args){
Scanner k = new Scanner(System.in);
while(true)
{
String s = k.nextLine();
int space = 0,c = 0;
for(c = 0;c<s.length();c++)
{
if(s.charAt(c)==' ')
{
space++;
}
}
Scanner b = new Scanner(s);
int [] v = new int [s.length()-space];
c = 0;
while(b.hasNextInt())
{
int i = b.nextInt();
v[c] = i;
c++;
}
int p = 1,chq = 0,save = 0,save1 = 0;
for(int t =0;t<v.length;t++)
{
if(!(v[t]>0))
{
chq = 1;
break;
}
}
while(p<v.length)
{
int max=0,min=0;
if(v[p-1]>v[p])
{
max = v[p-1];
min = v[p];
}
else
{
max = v[p];
min = v[p-1];
}
if(p==1)
{
save = max - min;
p++;
}
else
{
save1 = save;
save = max - min;
if((save==save1)||(save == (save1-1)))
{
p++;
}
else
{
chq = 1;
break;
}
}
}
if(chq == 0)
{
System.out.println("Jolly");
}
else
{
System.out.println("Not jolly");
}
}
}
}
Re: 10038 - Jolly Jumpers
Posted: Sat Feb 16, 2013 10:08 pm
by lbv
raj wrote:CAN ANYONE PLEASE TELL ME WHERE IS THE PROBLEM???
ONLINE JUDGE SAYS ITS WRONG ANSWER..............
Was the verdict "Wrong Answer" or "Runtime Error"?
For now, I can see that your code throws a
java.util.NoSuchElementException exception when it reaches the end of the input. Try changing this:
Code: Select all
while(true)
{
String s = k.nextLine();
// etc.
}
with something like:
Code: Select all
while(k.hasNextLine())
{
String s = k.nextLine();
// etc.
}