Page 27 of 30

Re: 10038 - Jolly Jumpers

Posted: Tue Jun 24, 2014 4:41 am
by 8kiwi8
changing cin.ignore(10000,'\n'); to cin.ignore(100000,'\n');

Code: Select all

Get AC....

Re: 10038 - Jolly Jumpers WA

Posted: Sat Jun 28, 2014 6:16 am
by lichtgestalt01
some useful test cases
Input:

Code: Select all

2 1 2 
4 1 4 3 1
4 1 4 2 3
5 1 4 2 -1 6
2 1 3
1 1
1 10
5 4 1 4 3 1
11 1 2 4 7 11 16 22 29 37 46 56  
3 2 1 3

Output:

Code: Select all

Jolly
Jolly
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly

Re: 10038 - Jolly Jumpers

Posted: Wed Jul 23, 2014 12:44 pm
by mratan16
I've tried about every test case I can find here but it still says WA.

Can anyone help?

Code: Select all

thank you so much for the help :) Got AC

Re: 10038 - Jolly Jumpers

Posted: Wed Jul 23, 2014 1:21 pm
by lighted
A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1.
Change this

Code: Select all

if(temp>1 && temp<=input-1){jolly[temp]=true;}
It must be

Code: Select all

if(temp>=1 && temp<=input-1){jolly[temp]=true;}
For each line of input, generate a line of output saying "Jolly" or "Not jolly".
Change this

Code: Select all

else{cout << "Not Jolly" << endl;}
It must be

Code: Select all

else{cout << "Not jolly" << endl;}
Don't forget to remove your code after getting accepted. 8)

Re: 10038 - Jolly Jumpers

Posted: Thu Jul 24, 2014 3:28 pm
by apcastelein
I'm having trouble with the IO in this problem. I enter the first line of numbers then I go to the next line and the program ends. It might be because I'm doing it in cmd. I've tried using "type UVa10038.in | UVa10038.exe" to input all data but I get similar results. My program doesn't print anything.

Code: Select all

I got AC, thanks very much for the help

Re: 10038 - Jolly Jumpers

Posted: Thu Jul 24, 2014 4:28 pm
by lighted
Can you see the semicolon after if expression. It was your problem. Remove it. :)

Code: Select all

 if(scanf("%d",&n)==0);
         break;
Your terminating condition doesn't work. Change this to

Code: Select all

if(scanf("%d",&n)==EOF)
         break;
But i prefer this way

Code: Select all

   while(scanf("%d",&n) == 1){
      //clear vector and set
      list.clear();
      s.clear();
Don't forget to remove your code after getting accepted. 8)

Re: 10038 - Jolly Jumpers

Posted: Fri Jul 25, 2014 11:02 am
by rafid059
helloneo wrote:"Not Jolly" should be "Not jolly" :)

Your comment saved my life! :D thanks!

Re: 10038 - Jolly Jumpers

Posted: Sun Aug 17, 2014 9:45 pm
by axelblaze
I'm getting WA. I don't get what's wrong with my code..
Its giving correct outputs for all critical inputs...

Code: Select all

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    int n,a,b,sum;
    while(cin>>n)
    {
        sum=((n*(n+1))/2)-n;
        cin>>a;
        b=a;
        for(int i=0;i<n-1;i++)
        {
            cin>>a;
            sum-=abs(a-b);
            b=a;
        }
        if(sum==0) cout<<"Jolly"<<endl;
        else cout<<"Not jolly"<<endl;
    }
    return 0;
}

Re: 10038 - Jolly Jumpers

Posted: Sun Aug 17, 2014 10:43 pm
by apcastelein
You're code checks if the differences sum to what they would sum to if each difference in the sequence was accounted for. However there are cases when the differences sum correctly but not all differences are accounted for.

Try this

1 1 4 7

This sequence isn't jolly but I believe your code will return that it is.

Re: 10038 - Jolly Jumpers

Posted: Wed Aug 20, 2014 6:04 pm
by RedCode119
This code is showing time limit exceeded, can't find out why, pls help me

Code: Select all

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

int main()
{
    int n,a,b,x,sub,old_sub,flag;

    while(scanf("%d", &n)!=EOF)
    {
        cin>>a>>b;
        n=n-2;
        old_sub=a-b;
        if(old_sub<0)
            old_sub=old_sub*(-1);
        a=b;
        flag=1;
        while(n)
        {
            cin>>x;
            sub=a-x;
            if(sub<0)
                sub=sub*(-1);
            a=x;
            if(old_sub==sub || old_sub-sub==1)
            {

            }
            else
            {
                flag=0;
            }
            old_sub=sub;
            n--;
        }
        if(flag)
        cout<<"Jolly"<<endl;
        else
            cout<<"Not Jolly"<<endl;
    }
    return 0;
}

Re: 10038 - Jolly Jumpers (Time limit exceeded)

Posted: Wed Aug 20, 2014 7:00 pm
by RedCode119
Can't find out why it's showing time llimit exceeded. here's the code

Code: Select all

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

int main()
{
    int n,a,b,x,sub,old_sub,flag;

    while(cin>>n)
    {
        cin>>a>>b;
        n=n-2;
        old_sub=abs(a-b);
        a=b;
        flag=1;
        while(n)
        {
            cin>>x;
            sub=abs(a-x);
            a=x;
            if(old_sub==sub || old_sub-sub==1)
            {

            }
            else
            {
                flag=0;
            }
            old_sub=sub;
            n--;
        }
        if(flag)
        cout<<"Jolly"<<endl;
        else
            cout<<"Not Jolly"<<endl;
    }
    return 0;
}

Re: 10038 - Jolly Jumpers

Posted: Wed Aug 20, 2014 7:01 pm
by lighted
Don't post twice. Change line to

Code: Select all

while(n > 0)
Maybe there can be only one number when n = 1. :)

Re: 10038 - Jolly Jumpers

Posted: Wed Aug 20, 2014 8:26 pm
by RedCode119
To lighted,
it's not working . srry 4 double post

Re: 10038 - Jolly Jumpers

Posted: Wed Aug 20, 2014 8:41 pm
by lighted

Code: Select all

flag=1;

while(n > 0)
{
  cin >> x;
It's not working to get accepted. :D
But it's working to avoid Time Limit Exceeded. It gets Wrong Answer. Check it again. :)

Re: 10038 - Jolly Jumpers WS

Posted: Thu Aug 21, 2014 9:08 am
by RedCode119
can't get why it's showing wrong answer.............

Code: Select all

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

int main()
{
    int n,a,b,x,sub,old_sub,flag,calc;
    while(cin>>n)
    {
        if(n==0)
            continue;
        flag=1;
        if(n==1)
        {
            cout<<"Jolly"<<endl;
            continue;
        }
        cin>>a>>b;
        old_sub=abs(a-b);
        if(old_sub!=1 && old_sub!=n-1)
        {
            flag=0;
        }
        a=b;
        n=n-2;
        while(n)
        {
            cin>>b;
            sub=abs(a-b);
            calc=abs(old_sub-sub);
            if(old_sub==sub || calc==1)
            {

            }
            else
            {
              flag=0;
            }
            old_sub=sub;
            a=b;
            n--;

        }
            if(flag)
                cout<<"Jolly"<<endl;
            else
                cout<<"Not Jolly"<<endl;
    }
    return 0;
}