CCC '03 J2 - Picture Perfect

View as PDF

Submit solution

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

Problem type
Canadian Computing Competition: 2003 Stage 1, Junior #2

Roy has a stack of student yearbook photos. He wants to lay the pictures on a flat surface edge-to-edge to form a filled rectangle with minimum perimeter. All photos must be fully visible. Each picture is a square with dimensions 1 unit by 1 unit.

For example, he would place 12 photos in the following configuration, where each photo is indicated with an X.

XXXX
XXXX
XXXX

Of course, he could orient them in the other direction, such as

XXX
XXX
XXX
XXX

which would have the same perimeter, 14 units.

Your program should repeatedly read a positive integer C, the number of pictures to be laid out. For each input, it should print the smallest possible perimeter for a filled rectangle that is formed by laying all the pictures edge-to-edge. Also print the dimensions of this rectangle.

You may assume that there are less than 65\,000 photos. An input value of C = 0 indicates that the program should terminate.

Sample Input

100
15
195
0

Sample Output

Minimum perimeter is 40 with dimensions 10 x 10
Minimum perimeter is 16 with dimensions 3 x 5
Minimum perimeter is 56 with dimensions 13 x 15

Comments


  • 0
    kresteodymium  commented on Feb. 5, 2021, 1:02 p.m.

    I keep getting an error that says that I have an unused variable. I'm not sure why that would give me an error. Can someone please take a look and guide me on this. :)

    Much appreciated and thanks, :)

    kresteodymium


    • 1
      WilliamWu277  commented on Feb. 5, 2021, 1:39 p.m. edited

      I believe that the main problem with your code is that you are printing a capital X as your multiplication sign instead of a lower case x. The unused variable warning comes from the fact that you are initializing int peri once before the for loop and again inside the for loop. Simply remove the int peri = 0 before the for loop and change your program so that it is printing lowercase x instead of uppercase X and it should AC.


      • 0
        kresteodymium  commented on Feb. 6, 2021, 7:57 p.m.

        Thank you so much WilliamWu277! It worked! :)


  • 0
    Tintin  commented on Jan. 1, 2021, 9:32 p.m.

    Can someone check my code, when I try the input on PyCharm it works fine but it doesn't seem to work on DMOJ


    • 2
      cabbagecabbagecabbage  commented on Jan. 2, 2021, 12:13 a.m.

      notice that you are outputting "Minimum perimeter is 32.0 with dimensions 6 x 10" indicating that you did division with "/" which returns a float instead of integer division "//" (line 13 in your most recent submission).

      as a side note i think they prefer people asking for help on the dmoj slack instead of the comment section


      • -4
        31501357  commented on Jan. 2, 2021, 11:00 p.m.

        This is why you just default to using //, or use python 2, or better yet, just don't use python at all.


  • -8
    WEAVER  commented on Nov. 23, 2020, 6:05 p.m.

    This comment is hidden due to too much negative feedback. Click here to view it.


  • -19
    KevinYangJ8  commented on April 17, 2020, 6:46 p.m. edited

    This comment is hidden due to too much negative feedback. Click here to view it.


    • -3
      Bisayo  commented on April 4, 2021, 9:24 p.m.

      why does this have so many downvotes


      • 1
        henrybaolol9  commented on April 5, 2021, 8:22 p.m.

        because he asked for the solution


  • -4
    Davy_Chu  commented on April 10, 2020, 5:37 p.m.

    Can someone check why my code does not work? I have tried all the test cases and it seems to run fine on repl.it for me. Thanks.


    • -4
      Xyene  commented on April 10, 2020, 10:07 p.m.

      "Mininum"


  • -1
    sobko  commented on April 3, 2019, 7:36 p.m. edited

    I only seem to be getting 80/100 with only one test case even though it appears to meet all the requirements? Anybody got any ideas?

    Edit: Nvm my code did not work for when there was only 1 picture