It's the information olympiad issue

Asked 2 years ago, Updated 2 years ago, 34 views

Information Olympiad melon field problem (http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=1520&sca=2060).

I looked at the answer sheet because I didn't know, but I was surprised to see a short code.

#include <stdio.h>

int main() {
    int K;
    scanf("%d", &K);

    int paper[500][500] = { 0, };
    int six[6][2] = { 0, };

    int farm = 0;

    int max_width = 0;
    int max_height = 0;


    for (int i = 0; i < 6; i++) {
        scanf("%d %d" , &six[i][0] , &six[i][1]);

        if (six[i][0] == 1 || six[i][0] == 2) {


            if (six[i][1] > max_width) {
                max_width = six[i][1];
            }
        }
        else if (six[i][0] == 3 || six[i][0] == 4) {


            if (six[i][1] > max_height) {
                max_height = six[i][1];
            }
        }

    }

    for (int i = 0; i < 5; i++) {

        farm += (six[i][1] * six[i + 1][1]);
    }

    farm += (six[0][1] * six[5][1]);

    farm -= max_width * max_height * 2;


    printf("%d" , farm * K);





}

But at the end,

    farm -= max_width * max_height * 2;

I couldn't understand this part no matter how hard I looked at it. I understand the process of cutting a square and combining it with a farm Why are you taking that part out?

I'd appreciate it if you could explain it in detail.

c oi

2022-09-22 17:59

1 Answers

The problem is that we're touring six hexagonal boundaries.

The solution is to find the area of the farm by accumulating the area value while traveling from any one line.

The given segment in the problem is 6 consecutive.

In either of the above two cases, it is in order. Let's say the first case.

From now on, draw a picture and copy it. I need six colors.

Color adjacent values multiplied by each other. (For statement)

Finally, use the value multiplied by the 0th value. (corresponding to six[0][1] * six[5][1])

If you've colored all of the six areas above in different colors, all of the other areas will be painted three times, except for the concave.

The concave part will be painted twice.

So you subtract the width and width of the max twice. (max_width * max_height * 2)

Then only the area inside the hexagon that's been painted three times will remain.


2022-09-22 17:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.