Page 13 of 30
Posted: Fri Apr 27, 2007 9:18 pm
by Rocky
but my ac programm output as follows...
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..
but for the input 1 2 the differece will not match with 1 to 0 ..so not jolly is it ok...
GOOD LUCK
Rocky
jolly jumper_easy but not accepted
Posted: Thu May 17, 2007 1:04 pm
by azzo71
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;
}
Posted: Tue May 22, 2007 2:52 pm
by misof
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.
Posted: Tue May 22, 2007 7:51 pm
by azzo71

Thanks misof
I really appreciate it.
but still WA
Posted: Wed May 23, 2007 3:48 pm
by newton
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
may u expalin please?
" i like logic "
Posted: Wed May 23, 2007 10:05 pm
by Jan
The answer is 'Joly' for 1 2. Rocky, read the description again.
Posted: Thu May 24, 2007 10:04 am
by sohel
Jan wrote:The answer is 'Joly' for 1 2.
The answer for
1 2 is actually Jol
ly.

Posted: Sun May 27, 2007 12:49 pm
by jainal cse du
I don't understand Why Judge giving me WA.
Help me please
Posted: Sun May 27, 2007 12:59 pm
by helloneo
Try this case..
My output is..
Posted: Mon Jun 04, 2007 11:47 am
by jainal cse du
Thanx,
I have got AC.....

Posted: Wed Jun 06, 2007 2:51 pm
by Waddle
[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]
Posted: Wed Jun 06, 2007 2:51 pm
by Waddle
why the third case " 10 1 2 3 4 5 6 7 8 9 10" Not jolly ?[/quote]
Posted: Wed Jun 06, 2007 5:33 pm
by sohel
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?
Posted: Wed Jun 06, 2007 5:58 pm
by Waddle
[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
Posted: Wed Jun 20, 2007 10:24 am
by sohel
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 ??