Is that a wrong idea? Is that the wrong way?

Asked 2 years ago, Updated 2 years ago, 20 views

If there is a matrix of img_3 as shown in the figure below, it is set to go down in the top row, but when it goes down, it is set to go down in the range of +-1. Instead, I went down and picked the lowest part of the range and let it go down! But the algorithm doesn't work as I thought.

Is there a problem finding the minimum??

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////p>

intsd = 0; // the final value to select

int* ssdd = new int[y]; //1 For each column, store the stem contents up to y-1

For (inti = 0; i < y; i++) { // Initialize stem content
    ssdd[i] = 0;
}



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

    intcol = i; //The column value of the previously selected row

    int min = 100000; // To find the minimum value

    intim = 0;// Space to temporarily store column values

    ssdd[i] +=img_3[0][i]; // Preserve each column value in advance in the first row

    For (int w = 1; w < x; w++) { // Start the scan from the second row

        If (col == 0) { // when the previously selected column is the leftmost

            for (int z = col; z <= col + 1; z++) {

                if (img_3[w][z] < min) {
                    min = img_3[w][z];
                    im = z;
                }
            }
            col = im;
            ssdd[i] += img_3[w][col];
            continue;

        }

        If (col == y - 1) { // when the previously selected column is right

            for (int z = col - 1; z <= col; z++) {
                if (img_3[w][z] < min) {
                    min = img_3[w][z];
                }
                im = z;
            }

            col = im;
            ssdd[i] += img_3[w][col];
            continue;

        }


        For (int z = col - 1; z < = col + 1; z++) { //Just in the middle

            if (img_3[w][z] < min) {
                min = img_3[w][z];
            }
            im = z;

        }

        col = im;
        ssdd[i] += img_3[w][col];

    }

}


For (inti = 0; i < y; i++) { // for temporary verification
    cout << ssdd[i] << "    ";
}


ssd = ssdd[0];
For (inti = 1; i < y; i++) { // Find the minimum value
    if (ssdd[i] < ssd) {
        ssd = ssdd[i];
    }
}




delete[]ssdd; //Return

c++

2022-09-20 16:53

1 Answers

I solved it after thinking about it! I'll delete it when time passes!


2022-09-20 16:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.