## 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

Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:
but my ac programm output as follows...

Code: Select all

``````1 2
Not Jolly
``````
as i remember the problem says that the sequence contain all the succesive difference 1 to n-1...
if n=1..then it should contain alll the differnece 1 to 0(1-1)..is'nt it!!!
so if n=1,the it will be jolly if the input is as follows..

Code: Select all

``````1 1
``````
but for the input 1 2 the differece will not match with 1 to 0 ..so not jolly is it ok...

GOOD LUCK
Rocky

azzo71
New poster
Posts: 2
Joined: Thu May 17, 2007 12:58 pm

### jolly jumper_easy but not accepted

the system always give me WA , i dont know why.
any ideas...

/*
PROGRAMMING CHALLENGES
The Programming Contest Training Manual
IBM
2.8 Problems
2.8.1 Jolly Jumpers
*/

#include <iostream>
#include <cstdlib>
#include <vector>
#include <list>
#include <cmath>
using namespace std;

int main()
{
vector<int> nums;
list<int> res;
int seq, num,result;
int num1,num2;

cin >> seq;
if(seq <= 0 || seq > 3000)
exit(0);

nums.reserve(seq);

//To store the input in nums
for(int i = 0 ;i < seq;i++)
{
cin >> num;
nums.push_back(num);
}

//to get the difference and store it in (res) vectore variable
vector<int>::iterator iter;
for(iter = nums.begin();iter != nums.end();iter++)
{
num1 = *iter;
iter++;
if(iter == nums.end())
break;

num2 = *iter;
iter--;
result = num1 - num2;
res.push_back(abs(result));//store the absolute value of result
}

res.sort();
res.unique();

for(int i = res.size();i > 0;i--)
{
--seq;
if(res.back() == seq)
{
res.pop_back();
}
else
{
cout << "Not jolly" << endl;
exit(1);
}
}
cout << "jolly" << endl;

return 0;
}
Last edited by azzo71 on Tue May 22, 2007 8:28 pm, edited 1 time in total.

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm
One mistake I see is that the "j" in your "jolly" is lowercase but should be uppercase.
Learn to always test your solution against the example I/O before submitting

Edit: Also, change the exit(1) to exit(0), your program is supposed to terminate normally under all conditions.

azzo71
New poster
Posts: 2
Joined: Thu May 17, 2007 12:58 pm
Thanks misof
I really appreciate it.

but still WA

newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:
hi rocky

in the problem there is a comments....

Code: Select all

``````The definition implies that any sequence of a single integer is a jolly jumper.
``````

so how

Code: Select all

``````1 2

Not joly
``````

may u expalin please?

" i like logic "

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
The answer is 'Joly' for 1 2. Rocky, read the description again.
Ami ekhono shopno dekhi...
HomePage

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York
Jan wrote:The answer is 'Joly' for 1 2.
The answer for 1 2 is actually Jolly.

jainal cse du
New poster
Posts: 23
Joined: Thu Jul 27, 2006 2:43 pm
Location: University of Dhaka,Bangladesh
I don't understand Why Judge giving me WA.
Help me please

Code: Select all

``````
removed after AC

``````
Last edited by jainal cse du on Mon Jun 04, 2007 11:46 am, edited 1 time in total.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
Try this case..

Code: Select all

``4 1 3 5 7``
My output is..

Code: Select all

``Not jolly``

jainal cse du
New poster
Posts: 23
Joined: Thu Jul 27, 2006 2:43 pm
Location: University of Dhaka,Bangladesh
Thanx,
I have got AC.....

Waddle
New poster
Posts: 22
Joined: Thu Jan 25, 2007 3:54 pm
Location: Taiwan
Contact:
[quote="chunyi81"]My AC program has a slightly different output than the one above.

My AC program outputs:
[code]
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Not jolly
Jolly
[/code]

As for which one is correct, it all comes down to the following input:
[code]
1 2
[/code]

Since there is only one integer, shouldn't the correct output be "Jolly"?[/quote][quote]

why the third case " 10 1 2 3 4 5 6 7 8 9 10" Not jolly ?[/quote]

Waddle
New poster
Posts: 22
Joined: Thu Jan 25, 2007 3:54 pm
Location: Taiwan
Contact:
why the third case " 10 1 2 3 4 5 6 7 8 9 10" Not jolly ?[/quote]

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York
Waddle wrote:why the third case " 10 1 2 3 4 5 6 7 8 9 10" Not jolly ?
What makes you think [10 1 2 3 4 5 6 7 8 9 10] is Jolly?

Waddle
New poster
Posts: 22
Joined: Thu Jan 25, 2007 3:54 pm
Location: Taiwan
Contact:
[quote="sohel"][quote="Waddle"]why the third case " 10 1 2 3 4 5 6 7 8 9 10" Not jolly ?[/quote]

What makes you think [10 1 2 3 4 5 6 7 8 9 10] is Jolly?[/quote]
10-9=1
9-8=1
8-7=1
7-6=1
6-5=1
5-4=1
4-3=1
3-2=1
2-1=1
1 <= All of them <= n-1 = 9

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York
You have slightly misunderstood the problem.
Rereading the problem statement might help!

The differences between adjacent numbers must cover all the numbers from 1 to n-1.

For the above case, only 1 is covered!! What about 2 3 4 ... 8 9 ??