#include <cmath>
#include <vector>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param n int整型
* @param k int整型
* @return int整型vector<vector<>>
*/
vector<vector<int> > rotateII(int n, int k) {
// write code here
// 模拟
vector<vector<int>> ans;
for(int i=1; i<=n; ++i)
{
vector<int> temp;
int t = 1;
for(int j=1; j<=n; ++j)
temp.emplace_back((i-1)*n+j);
ans.emplace_back(temp);
}
// 可以将向做和向上分开执行
// 执行向左移动
for(int i=0; i<k; ++i)
{
for(int r=0; r<n; ++r)
{
int temp = ans[r][0];
for(int c=0; c+1<n; ++c)
ans[r][c] = ans[r][c+1];
ans[r][n-1] = temp;
}
}
// 执行向上移动
for(int i=0; i<k; ++i)
{
for(int c=0; c<n; ++c)
{
int temp = ans[0][c];
for(int r=0; r+1<n; ++r)
ans[r][c] = ans[r+1][c];
ans[n-1][c] = temp;
}
}
return ans;
}
};