CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » Manipal Institute of Technology » Marbles

Marbles

Problem code: MANIP5

  • All Submissions

Malcom and Angus own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the collection in half. But unfortunately, some of the marbles are larger, or more beautiful than others. So, Malcom and Angus start by assigning a value, a natural number between one and six, to each marble. Now they want to divide the marbles so that each of them gets the same total value. Unfortunately, they realize that it might be impossible to divide the marbles in this way sometimes even if the total value of all marbles is even. For example, if there are one marble of value 1, one of value 3 ,three of value 4 and one of value 6 ,then they can be split into sets of equal value (Set 1 = { 1,0,0,1,0,1} Set 2 = { 0,0,1,2,0,0}) So, they ask you to write a program that checks whether it is possible to split the marbles fairly.

Input

The first line consists of t (1<= t<= 50) the number of test cases. Then t test cases follow. Each line in the test case describes one collection of marbles to be divided. The lines consist of six non-negative integers n1 , n2 , n3 , n4 , n5 , n6 where ni is the number of marbles of value i. So, the example from above would be described by the input-line 1 0 1 3 0 1 . The maximum number of marbles of each priority is 20.

Output

For each test case output a single line with the word Yes if the marbles can be divided or No" if they can't be divided.

Sample

Input
5
1 0 1 2 0 0
1 0 0 0 1 1
2 1 2 1 2 1
1 0 1 3 0 1
20 20 20 20 20

Output
No
Yes
No
Yes
Yes


Author: admin
Date Added: 31-08-2009
Time Limit: 5 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

it seems theres something

akantev @ 9 Sep 2009 03:20 PM

it seems theres something wrong with the case  2 1 2 1 2 1.

i can have set1=2 0 1 1 0 1 and set2=0 1 1 0 2 0. doesnt this satisfy the reqd condition?

please correct me if im wrong...

Why are there only 5 integers

kunaljain @ 9 Sep 2009 04:21 PM

Why are there only 5 integers in the last case?

And as the above comment says, the answer for 3rd case is Yes.

hi,   last has 6 20s and the

sanjay_ankur @ 9 Sep 2009 04:41 PM

hi,

 

last has 6 20s and the answer to the 3rd is a YES.

 

regards,

 

Ankur (event co-ordinator)

The third sample is wrong.

kunaljain @ 9 Sep 2009 08:44 PM

The third sample is wrong. The answer should be Yes.

I want the admins to check. I am damn sure about my solution..

Third one is WRONG. it is

Karan1337 @ 9 Sep 2009 09:06 PM

Third one is WRONG. it is definitely "YES".  i coded the problem twice and yet the answer is same. Please make appropriate changes so that the answer is shown as "Correct".

Er, take a look at the

lonewolf @ 9 Sep 2009 09:29 PM

Er, take a look at the comments section too. In fact, the one by Ankur just right above your own comment.

but still the judge gives

kunaljain @ 9 Sep 2009 09:41 PM

but still the judge gives incorrect submission, and i am damn sure that my solution gives correct result for all the input cases...So there may be something wrong in your result...

Wasted one hell of a time on

Karan1337 @ 9 Sep 2009 09:44 PM

Wasted one hell of a time on this problem, and even after getting all answers correct ( twice), as Kunal said, the judge says "Wrong Answer". Something should be done for this, and that too quick.

 hi, I've just contacted the

sanjay_ankur @ 9 Sep 2009 11:01 PM

 hi,

I've just contacted the author of the problem. He checked the solutions. The outputs are correct. 

regards,

Ankur (event- co-ordinator)

#include<iostream> #include<s

Ankit1191 @ 10 Sep 2009 04:06 PM

#include<iostream>
#include<stdlib>
struct marble{
    int type1;
    int type2;
    int type3;
    int type4;
    int type5;
    int type6;
    void input()
    {
        cin>>type1>>type2>>type3>>type4>>type5>>type6;
    }
    int total_val()
    {
        return(type1*1+type2*2+type3*3+type4*4+type5*5+type6*6);
    }
    int val(int i,int j,int k,int l,int m,int n)
    {
        return(i*type1+j*type2+k*type3+l*type4+m*type5+n*type6);
    }
    int split();
};

int marble::split()
    {
        int total = total_val();
        if(total%2!=0)
            return 0;
        for(int i=0;i<=type1;i++)
            for(int j=0;j<=type2;j++)
                for(int k=0;k<=type3;k++)
                    for(int l=0;l<=type4;l++)
                        for(int m=0;m<=type5;m++)
                            for(int n=0;n<=type6;n++)
                            {
                                if(val(i,j,k,l,m,n)==val(type1-i,type2-j,type3-k,type4-l,type5-m,type6-n))

                                    return 1;
                            }
    }

main()
{

    using namespace std;
    int total_cases;
    marble *marbles;
    marbles=(marble*)malloc(total_cases*sizeof(marble));
    cin>>total_cases;
    for(int i=0;i<total_cases;i++)
        marbles[i].input();
    for(i=0;i<total_cases;i++)
    {
        if(marbles[i].split()==1)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
}


 

Is the above code correct??

Ankit1191 @ 10 Sep 2009 04:07 PM

Is the above code correct?? If not then please give corrections....ty

I got my error ......i forgot

Ankit1191 @ 10 Sep 2009 04:18 PM

I got my error ......i forgot to place else return 0; in split() function

 

The CORRECT program is as

Ankit1191 @ 10 Sep 2009 04:59 PM

The CORRECT program is as follows:

 

 

 

 

#include<iostream>
#include<stdlib>
struct marble{
    int type1;
    int type2;
    int type3;
    int type4;
    int type5;
    int type6;
    void input()
    {
        cin>>type1>>type2>>type3>>type4>>type5>>type6;
    }
    int total_val()
    {
        return(type1*1+type2*2+type3*3+type4*4+type5*5+type6*6);
    }
    int val(int i,int j,int k,int l,int m,int n)
    {
        return(i*1+j*2+k*3+l*4+m*5+n*6);
    }
    int split();
};

int marble::split()
{
        int tobereturned = 0;
        int total = total_val();
        if(total%2!=0)
            return tobereturned;
        int half_val=total/2;
        for(int i=0;i<=type1;i++)
            for(int j=0;j<=type2;j++)
                for(int k=0;k<=type3;k++)
                    for(int l=0;l<=type4;l++)
                        for(int m=0;m<=type5;m++)
                            for(int n=0;n<=type6;n++)
                                    if(val(i,j,k,l,m,n) == half_val)
                                        tobereturned = 1;

    return tobereturned;
}

main()
{

    using namespace std;
    int total_cases;
    marble *marbles;
    marbles=(marble*)malloc(total_cases*sizeof(marble));
    cin>>total_cases;
    for(int i=0;i<total_cases;i++)
        marbles[i].input();
    for(i=0;i<total_cases;i++)
    {
        if(marbles[i].split()==1)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
}


 

You are not supposed to post

ashishanand @ 10 Sep 2009 07:24 PM

You are not supposed to post codes here.So for future plz make sure you dont repeat this.Anyways first atleast run the code.The logic is right but efficiency is also taken into consideration here, using 6 nested for loops(have you considered the time it will take if there are 50 test cases).Think of Dynamic programming for solving this question or atleast use a break inside when you have found the value once.And what you have written will give segmentation fault if appropriate changes are not made to it.Also for the case when the values of all n1...n6 are 0  the answer should be No .

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com