Page 24 of 30

Re: 10038 - Jolly Jumpers

Posted: Sat Nov 09, 2013 5:13 am
by d3nd0h
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;
}

Re: 10038 - Jolly Jumpers

Posted: Tue Nov 12, 2013 12:11 am
by brianfry713
4 1 3 2 4 is Not jolly

Re: 10038 - Jolly Jumpers

Posted: Mon Nov 25, 2013 6:28 pm
by Ovro
Why am i getting Wa? Can anyone help me?

Code: Select all

#Ac

Re: 10038 - Jolly Jumpers

Posted: Tue Nov 26, 2013 2:33 am
by brianfry713
You need to initialize differ

Re: 10038 - Jolly Jumpers

Posted: Tue Nov 26, 2013 5:16 am
by Ovro
Thanx a lot sir. I should have figured it out myself. :)

Re: 10038 - Jolly Jumpers

Posted: Wed Dec 04, 2013 12:08 am
by brianfry713
4 1 4 3 5 is Jolly

Re: 10038 - Jolly Jumpers

Posted: Sun Dec 08, 2013 12:05 pm
by abbir.ku
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 .

Re: 10038 - Jolly Jumpers

Posted: Mon Dec 09, 2013 11:47 pm
by brianfry713
3 1 3 6 is Not jolly

Re: 10038 - Jolly Jumpers

Posted: Mon Dec 16, 2013 6:36 pm
by arkhels
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;
}

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

Posted: Tue Dec 17, 2013 5:48 pm
by unreleased
#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;
}

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

Posted: Tue Dec 17, 2013 6:42 pm
by unreleased
#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;
}

Re: 10038 - Jolly Jumpers

Posted: Tue Dec 17, 2013 11:18 pm
by brianfry713
4 1 4 3 5 is Jolly

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

Posted: Thu Dec 19, 2013 12:19 am
by brianfry713
4 1 3 5 7 is Not jolly

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

Posted: Thu Dec 19, 2013 1:07 am
by brianfry713
Don't double post

WA in Problem E: Jolly Jumpers 10038

Posted: Tue Jan 28, 2014 1:49 pm
by m1m6
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;


}