Sort by

recency

|

782 Discussions

|

  • + 0 comments

    Sheffield locksmith provides professional and reliable locksmith services for homes, offices, and vehicles, ensuring security and peace of mind. From emergency lockouts to lock repairs and replacements, skilled technicians deliver fast and efficient solutions. Just like understanding matrix layer rotation requires precision and careful handling, expert locksmiths handle every lock with accuracy and expertise. Trust Sheffield locksmith for dependable service, protecting your property with professionalism, skill, and lasting security every time.

  • + 0 comments

    Leeds locksmith provides expert and reliable locksmith services for homes, offices, and vehicles, ensuring your property stays secure at all times. From emergency lockouts to lock repairs and replacements, skilled technicians deliver fast and efficient solutions. Just like understanding matrix layer rotation requires precision and careful execution, professional locksmiths handle every task with accuracy and expertise. Trust Bradford locksmith for dependable service, enhanced security, and peace of mind every time.

  • + 0 comments

    How is the program supposed to handle a 5x3 matrix? The center has a 3-element line, and while thinking about taking a break at luxury villas in Florence, which direction do elements on the line get shifted? EDIT: I guess the min(m,n) % 2 = 0 means this scenario never comes up?

  • + 0 comments

    Last 2 for loops were for debugging, you only need the second one for the actual solution breast lift chicago

  • + 0 comments

    They called me a mad man. Single pass, 1 nested loop, let's goooooooooo!

    So, what we are doing, since we already have the matrix, is calculating the location of the number from the original matrix that should fall on the position we are currently printing. So, instead of transforming the matrix, we are kind of going in the oposite directioin and figuring out what number would be where in the final matrix rather than transforming it.

    (The amount of times those ifs were tweaked is not up for discussion.)

    Also, do beware, this is not a pretty sight.

    void matrixRotation(vector<vector<int>> matrix, int r) {
        int row = matrix.size(), col = matrix[0].size();
        
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                
                int layer = min({i, j, row-1-i, col-1-j});
                
                int top = layer, left = layer;
                int bottom = row-1-layer, right = col-1-layer;
                
                int perimeter = 2 * ((bottom-top) + (right-left));
                
                int idx = 0;
                if (i == top){ 
                    idx = j-left;
                }else if (j == right){
                    idx = (right-left) + (i-top);
                }else if (i == bottom){ 
                    idx = (right-left) + (bottom-top) + (right-j);
                }else{ 
                    idx = (right-left) + (bottom-top) + (right-left) + (bottom-i);
                }
                
                int newIdx = (idx + r) % perimeter;
                
                int x, y;
                if (newIdx < (right-left)){ 
                    x = top; 
                    y = left + newIdx; 
                }else if (newIdx < (right-left) + (bottom-top)){ 
                    x = top + (newIdx - (right-left)); 
                    y = right; 
                }else if (newIdx < (right-left)*2 + (bottom-top)){ 
                    x = bottom; 
                    y = right - (newIdx - ((right-left)+(bottom-top))); 
                }else{ 
                    x = bottom - (newIdx - ((right-left)*2 + (bottom-top))); 
                    y = left; 
                }
                
                cout << matrix[x][y] << " ";
            }
            cout << endl;
        }
    }