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

8kiwi8
New poster
Posts: 1
Joined: Tue Jun 24, 2014 4:08 am

Re: 10038 - Jolly Jumpers

Post by 8kiwi8 »

changing cin.ignore(10000,'\n'); to cin.ignore(100000,'\n');

Code: Select all

Get AC....
lichtgestalt01
New poster
Posts: 4
Joined: Sun Jun 22, 2014 6:00 am

Re: 10038 - Jolly Jumpers WA

Post 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
mratan16
New poster
Posts: 21
Joined: Fri May 16, 2014 12:36 am

Re: 10038 - Jolly Jumpers

Post 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
Last edited by mratan16 on Wed Jul 23, 2014 2:10 pm, edited 1 time in total.
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10038 - Jolly Jumpers

Post 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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
apcastelein
New poster
Posts: 15
Joined: Wed Jul 23, 2014 12:57 am

Re: 10038 - Jolly Jumpers

Post 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
Last edited by apcastelein on Thu Jul 24, 2014 5:08 pm, edited 1 time in total.
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10038 - Jolly Jumpers

Post 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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
rafid059
New poster
Posts: 13
Joined: Thu Feb 27, 2014 6:35 pm

Re: 10038 - Jolly Jumpers

Post by rafid059 »

helloneo wrote:"Not Jolly" should be "Not jolly" :)

Your comment saved my life! :D thanks!
axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

Re: 10038 - Jolly Jumpers

Post 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;
}
apcastelein
New poster
Posts: 15
Joined: Wed Jul 23, 2014 12:57 am

Re: 10038 - Jolly Jumpers

Post 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.
RedCode119
New poster
Posts: 13
Joined: Tue Jul 08, 2014 7:14 pm

Re: 10038 - Jolly Jumpers

Post 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;
}
RedCode119
New poster
Posts: 13
Joined: Tue Jul 08, 2014 7:14 pm

Re: 10038 - Jolly Jumpers (Time limit exceeded)

Post 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;
}
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10038 - Jolly Jumpers

Post 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. :)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
RedCode119
New poster
Posts: 13
Joined: Tue Jul 08, 2014 7:14 pm

Re: 10038 - Jolly Jumpers

Post by RedCode119 »

To lighted,
it's not working . srry 4 double post
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10038 - Jolly Jumpers

Post 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. :)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
RedCode119
New poster
Posts: 13
Joined: Tue Jul 08, 2014 7:14 pm

Re: 10038 - Jolly Jumpers WS

Post 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;
}
Post Reply

Return to “Volume 100 (10000-10099)”