CCC '04 J1 - Squares

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

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

Gigi likes to play with squares. She has a collection of equal-sized square tiles. Gigi wants to arrange some or all of her tiles on a table to form a solid square. What is the side length of the largest possible square that Gigi can build?

For example, when Gigi has 9 tiles she can use them all to build a square whose side length is 3. But when she has only 8 tiles, the largest square that she can build has side length 2.

Write a program that inputs the number of tiles and then prints out the maximum side length. You may assume that the number of tiles is less than ten thousand.

Sample Input 1

9

Sample Output 1

The largest square has side length 3.

Sample Input 2

8

Sample Output 2

The largest square has side length 2.

Sample Input 3

7535

Sample Output 3

The largest square has side length 86.

CCC problem statements in large part from the PEG OJ


Comments


  • 0
    fireheartjerry  commented on June 30, 2022, 3:56 p.m. edit 2

    lol kobortor used the Quake III fast inverse square root algorithm (comments are still the same in the code, check submissions for C, he is 2nd place).


  • 1
    Macruner  commented on March 19, 2022, 1:53 p.m.

    I don't understand why my code is not accepted. Its works in PyCharm, but not here (?) Please HELP ! ;)

    Thanks !


    • 1
      Kirito  commented on March 19, 2022, 4:02 p.m.
      1. Don't post code in the comments, anyone who has solved the problem can see your submissions.

      2. It is not sufficient to print only the number, you have to print the whole sentence.


      • 3
        Macruner  commented on March 19, 2022, 4:07 p.m.

        ok, thank you for the tip. Sorry, this is my first experiments here :)


  • 0
    moonshot2  commented on March 11, 2022, 5:16 p.m.

    Similar Dynamic programming.


  • 1
    Danielzhurandomguy  commented on Dec. 16, 2021, 4:31 p.m.

    uhhhh guys when i do my code, how do i cancel the space before the period??


    • 0
      henrybaolol9  commented on Dec. 16, 2021, 4:45 p.m.

      print(blah blah, sep="")


  • 3
    esyed510  commented on Oct. 18, 2020, 11:52 p.m.

    i spent half an hour big-braining some loop logic and then found out I could have just rounded down with int lol


  • 3
    MrRailgun  commented on Aug. 20, 2020, 4:53 p.m.

    My math is really bad, like i got a C+ for my grade, and i dont really know what the pattern is, could someone help me?


    • -1
      superalvin  commented on July 29, 2022, 12:46 a.m.

      you really should practice math-get a Complete Mathsmart book


    • -2
      Asorn  commented on Aug. 20, 2020, 5:53 p.m.

      try thinking about what square rooting a number does


    • 6
      noYou  commented on Aug. 20, 2020, 5:48 p.m. edit 2

      The area formula for a square of side length s is s^2 (s squared, or s*s). This problem is asking you, given a maximal value for the total area of the square, what is the maximal Integer side length that would fit? Integer means that there are no decimal side lengths in the square.

      In the example, if you had 8 blocks, only the side lengths 1 and 2 would fit (1*1 < 8, and 2*2 < 8). Of these, the two numbers, the maximum is 2 (because 2>1). Additionally, it can't be 3, or anything larger, because 3*3 = 9, and 9 > 8.


      • -1
        superalvin  commented on July 29, 2022, 12:47 a.m.

        very good calculation


  • 3
    Arihan10  commented on Dec. 22, 2018, 2:46 p.m.

    How do I do this? A simple nudge towards the right side would be nice.

    Thank you.


    • 10
      magicalsoup  commented on Dec. 22, 2018, 3:07 p.m.

      think about using sqrt


      • 6
        Arihan10  commented on Dec. 23, 2018, 12:49 p.m. edited

        Ohhhhh... Thank you so much! You are so smart! Of course... square roots will be used! I am literally so dumb! Thank you once again!


  • 19
    CoolNoobyBooby  commented on Aug. 23, 2018, 10:56 a.m.

    I didn't know what was wrong with my code for a long time, then I realized I forgot a period.


    • 8
      richardyou777  commented on Jan. 1, 2019, 12:21 a.m.

      That got me too. Don't forget the period after the side length of the square.


  • -20
    gabemok  commented on Nov. 21, 2014, 9:45 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • 18
      FatalEagle  commented on Nov. 21, 2014, 8:14 p.m.

      You are not receiving TLE but WA, meaning your program produced the wrong answer in 0.1 seconds. The output we show you is not the full output; the (clipped) means we only show a certain prefix of your output. For most problems this is the first 32 bytes.


      • 4
        loltrollkill  commented on Dec. 28, 2017, 5:35 p.m.

        Yay FatalEagle! my fav