CCC '10 J1 - What is n, Daddy?

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2010 Stage 1, Junior #1

Natalie is learning to count on her fingers. When her Daddy tells her a number n (1 \le n \le 10), she asks "What is n, Daddy?", by which she means "How many fingers should I hold up on each hand so that the total is n?"

To make matters simple, her Daddy gives her the correct finger representation according to the following rules:

  • the number may be represented on one or two hands;
  • if the number is represented on two hands, the larger number is given first.

For example, if Natalie asks "What is 4, Daddy?", her Dad may reply:

  • 4 is 4.
  • 4 is 3 and 1.
  • 4 is 2 and 2.

Your job is to make sure that Natalie's Daddy gives the correct number of answers.

Input Specification

The input will be a single integer i such that 1 \le i \le 10.

Output Specification

The output is the number of ways of producing that number on two hands, subject to the rules outlined above.

Sample Input

4

Output for Sample Input

3

Comments


  • -3
    ibex  commented on Dec. 1, 2024, 8:50 a.m. edited

    brute force goes wild:

            if (nNumber == 10)
            {
                System.out.println("1");
            }
            else if (nNumber == 9)
            {
                System.out.println("1");
            }
            else if (nNumber == 8)
            {
                System.out.println("2");
            }
            else if (nNumber == 7)
            {
                System.out.println("2");
            }
            else if (nNumber == 6)
            {
                System.out.println("3");
            }
            else if (nNumber == 5)
            {
                System.out.println("3");
            }
            else if (nNumber == 4)
            {
                System.out.println("3");
            }
            else if (nNumber == 3)
            {
                System.out.println("2");
            }
            else if (nNumber == 2)
            {
                System.out.println("2");
            }
            else if (nNumber == 1)
            {
                System.out.println("1");
            }
    

    • 2
      d  commented on Dec. 1, 2024, 10:39 a.m.

      please use an array


  • 1
    maxcruickshanks  commented on Nov. 19, 2024, 9:14 p.m.

    Since the original data were weak, an additional test case was added (that seems to have been omitted), and all submissions were rejudged.


    • 3
      thomas_li  commented on Nov. 20, 2024, 1:41 a.m.

      cant believe they forgot one of the ten cases


  • 2
    HisMonDon  commented on May 19, 2024, 11:48 p.m.

    Does anyone else think they're overcomplicating this?


    • 1
      781159  commented on Oct. 20, 2024, 3:59 a.m.

      yes bruh, im currently trying to find a better solution that is less than 70 lines of code lmao


  • 7
    Peter2023  commented on Jan. 10, 2024, 6:32 p.m. edited

    Did i just do a bunch of if else statements? maybe. Did I get 100%? yes.


    • 1
      781159  commented on Oct. 20, 2024, 4:00 a.m.

      not else if but just if because each condition in this case does not rely on the result of the other. but yea all that matters is the output ig but try to find a more efficient solution as that mindset would help on the senior contest


    • 1
      R_G  commented on Jan. 26, 2024, 12:08 a.m.

      fax


  • 1
    jorispos  commented on Feb. 19, 2019, 11:32 p.m.

    Can anyone check my solution? Is there any other (maybe mathematical) way to solve this?


    • 9
      kingW3  commented on Feb. 20, 2019, 12:02 a.m.

      If you're looking for more mathematical solution try thinking about the same problem but make the number of fingers also a parameter. Instead of it being 5 and make n\leq2k.


  • 201
    CarolChen  commented on Feb. 15, 2016, 4:55 p.m. edited

    Could not figure out what I was doing wrong then I remembered we have only 5 fingers.


    • 23
      MakanDey  commented on Feb. 22, 2018, 4:29 p.m.

      Oh darn I thought I had 40.


    • 3
      retronerd2016  commented on Nov. 2, 2017, 9:52 p.m.

      wait hold on the example says 3, what does 3 mean


      • 18
        xxsc  commented on July 4, 2018, 3:19 a.m. edited

        3 is the number of ways to show 4.

        4 is 4 is one way.

        4 is 3 and 1 is another.

        4 is 2 and 2 is the last one, because saying 4 is 1 and 3 would be the same as saying 4 is 3 and 1. Same goes with 4 is 0 and 4.

        EDIT:

        Yes CarolChen that is helpful.


    • 9
      Alicia  commented on Nov. 1, 2017, 3:59 a.m. edited

      CarolChen that's a very helpful hint, thanks