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

d3nd0h
New poster
Posts: 8
Joined: Sun Nov 03, 2013 3:39 am

Re: 10038 - Jolly Jumpers

Post by d3nd0h » Sat Nov 09, 2013 5:13 am

oh thanks..

I have left the newline character after each output then can u tell me what's wrong is with my code?
If I did wrong interpret the problem please tell me thx..

Code: Select all

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int n;
	vector<long long> diff;
	while(scanf("%d",&n)!=EOF){
		bool jolly=0;
		long long before;
		scanf("%lld",&before);
		for(int i=1;i<n;i++){
			long long after;
			scanf("%lld",&after);
			diff.push_back(abs(after-before));
			before=after;
		}
		sort(diff.begin(),diff.end());
		if(diff.back()>=n){
			jolly=0;
		}else if(n==1){
			jolly=1;
		}else if(n!=0){
			for(int i=1;i<n-1;i++){
				if(diff[i-1]==i){
					jolly=1;continue;
				}
				else{
					jolly=0;break;
				}
			}
		}else jolly=0;
		if(jolly) printf("Jolly\n");
		else printf("Not jolly\n");
		diff.clear();
	}
	
	return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Tue Nov 12, 2013 12:11 am

4 1 3 2 4 is Not jolly
Check input and AC output for thousands of problems on uDebug!

Ovro
New poster
Posts: 12
Joined: Mon Nov 11, 2013 8:30 am

Re: 10038 - Jolly Jumpers

Post by Ovro » Mon Nov 25, 2013 6:28 pm

Why am i getting Wa? Can anyone help me?

Code: Select all

#Ac
Last edited by Ovro on Tue Nov 26, 2013 5:17 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Tue Nov 26, 2013 2:33 am

You need to initialize differ
Check input and AC output for thousands of problems on uDebug!

Ovro
New poster
Posts: 12
Joined: Mon Nov 11, 2013 8:30 am

Re: 10038 - Jolly Jumpers

Post by Ovro » Tue Nov 26, 2013 5:16 am

Thanx a lot sir. I should have figured it out myself. :)

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Wed Dec 04, 2013 12:08 am

4 1 4 3 5 is Jolly
Check input and AC output for thousands of problems on uDebug!

abbir.ku
New poster
Posts: 3
Joined: Sat Nov 09, 2013 10:04 am

Re: 10038 - Jolly Jumpers

Post by abbir.ku » Sun Dec 08, 2013 12:05 pm

For the input 3 1 3 6 the answer is jolly I think . After having some trouble I figure out one just have to check absolute difference is 1 or not .

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Mon Dec 09, 2013 11:47 pm

3 1 3 6 is Not jolly
Check input and AC output for thousands of problems on uDebug!

arkhels
New poster
Posts: 4
Joined: Mon Dec 16, 2013 6:32 pm

Re: 10038 - Jolly Jumpers

Post by arkhels » Mon Dec 16, 2013 6:36 pm

anyone can help mee? I still didn't realize where my mistake, my code still gave me WA ....

#include<cstdio>
#include<iostream>
#include <cmath>

using namespace std;

int n,arr[3010],k,x;

int main () {
while (scanf("%d",&n) != EOF ) {
for (int i =0; i <n ; i++) {
scanf("%d",&arr);
}

bool nilai=true; k=0;
for (int i=0; i < n-1; i++) {
x=arr[i+1]-arr;
x= abs(x);
k++;
if (x==n-k) {continue;}
else {nilai =false; break;}

}

if (n==1) {nilai = true;}

if (nilai) {printf("Jolly\n");}
else {printf("Not jolly\n");}
}



return 0;
}

unreleased
New poster
Posts: 16
Joined: Sun Nov 10, 2013 7:41 pm

UVa 10038 (jolly jumper)...... whats wrong in my code?? :p

Post by unreleased » Tue Dec 17, 2013 5:48 pm

#include<stdio.h>
int main()
{
int i, j, k , cs, num,sum1,sum2;
int rem[3010];
while(scanf("%d", &cs)!=EOF)
{
j=0;
sum1=0;
for(i=0; i<cs; i++)
{
scanf("%d", &num);
rem=abs(num-j);
j=num;
}

for(k=1; k<cs; k++)
{
sum1+=rem[k];
}

sum2=cs*(cs-1)/2;
if(sum1==sum2)
printf("Jolly\n");
else
printf("Not jolly\n");
}
return 0;
}

unreleased
New poster
Posts: 16
Joined: Sun Nov 10, 2013 7:41 pm

UVa 10038 (jolly jumper)...... whats wrong in my code?? :p

Post by unreleased » Tue Dec 17, 2013 6:42 pm

#include<stdio.h>
int main()
{
int i, j, k , cs, num,sum1,sum2;
int rem[3010];
while(scanf("%d", &cs)!=EOF)
{
j=0;
sum1=0;
for(i=0; i<cs; i++)
{
scanf("%d", &num);
rem=abs(num-j);
j=num;
}

for(k=1; k<cs; k++)
{
sum1+=rem[k];
}

sum2=cs*(cs-1)/2;
if(sum1==sum2)
printf("Jolly\n");
else
printf("Not jolly\n");
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Tue Dec 17, 2013 11:18 pm

4 1 4 3 5 is Jolly
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVa 10038 (jolly jumper)...... whats wrong in my code??

Post by brianfry713 » Thu Dec 19, 2013 12:19 am

4 1 3 5 7 is Not jolly
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVa 10038 (jolly jumper)...... whats wrong in my code??

Post by brianfry713 » Thu Dec 19, 2013 1:07 am

Don't double post
Check input and AC output for thousands of problems on uDebug!

m1m6
New poster
Posts: 2
Joined: Mon Jan 27, 2014 12:44 am

WA in Problem E: Jolly Jumpers 10038

Post by m1m6 » Tue Jan 28, 2014 1:49 pm

why i got WA answer in jully jumber ....

the problem ask to find two successive elements their difference BW 1 to n-1

whta's the wrong !!!

Code: Select all

#include <iostream>
#include<stack>
#include <cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;



bool findR(int x,stack<int>s)
{
	while (!s.empty())
	{
		if (s.top() == x)
			return true;
		else
			s.pop();
	}
	
	return false;
}


int  main()
{

	int n;
	int x;
	stack<int> ss;
	bool isj = true;
	cin >> n;
	int *arr;
	
	while (cin )
	{
		if (n > 0)
		{
			 arr = new int[n];
			if (n == 1)
			{
				cin >> x;
				isj = true;
			}
			else
			{

				for (int i = 0; i < n; i++)
					cin >> arr[i];
	
		
				for (int i = 0; i < n-1; i++)
				{
					int c;
					//if (i<n)
					 c = abs(arr[i] - arr[i + 1]);

					if (n == 2)
					{
						if (abs(arr[0] - arr[1]) == 1)
							isj = true;
					}
					else
					{

						if (ss.empty())
							ss.push(c);
						else
						if (findR(c, ss))
							isj = false;

					}

					if (abs(arr[i] - arr[i + 1]) <= 0 || abs(arr[i] - arr[i + 1]) >= (n))
					{
						isj = false;
						break;
					}
				}
			}
			if (isj)
				cout << "Jolly" << endl;
			else
				cout << "Not jolly" << endl;
			
		}
		arr = NULL;
		if (ss.size()>0)
		while (!ss.empty())
			ss.pop();
		isj = true;

		cin >> n;
		
	}

	system("pause");
	return 0;


}
Last edited by m1m6 on Wed Jan 29, 2014 12:39 am, edited 1 time in total.

Post Reply

Return to “Volume 100 (10000-10099)”