文章

25

粉丝

0

获赞

132

访问

3.2k

头像
旋转矩阵 - 北航 题解:
P1377 北京航空航天大学机试题
发布于2026年2月2日 17:50
阅读数 405

#include<bits/stdc++.h>
using namespace std;
//旋转一次90度的
void rot(vector<vector<int>>& matrix){
    int left = 0,right = matrix.size()-1;
    while(left<right){
        for(int i = 0;i<right-left;i++){
            int top = left,bottom = right;
            int topleft = matrix[top][left+i];//保存左上角的值
            matrix[top][left+i] = matrix[bottom-i][left];//左下角元素旋转到左上角
            matrix[bottom-i][left] = matrix[bottom][right-i];//右下角元素旋转到左下角
            matrix[bottom][right-i] = matrix[top+i][right];//右上角元素旋转到右下角
            matrix[top+i][right] = topleft;//左上角元素旋转到右上角
        }
 &nb...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发