洛谷P4924 [1007] 魔法少女小Scarlet 题解
洛谷P4924 [1007] 魔法少女小Scarlet 题解
思路
通过模拟几次顺时针和逆时针的转换,不难发现每次顺时针旋转后,第\(i\)行的内容往往就与原来的第\(i\)列内容有关,如下表:
| 1 | 2 | 3 |
|---|---|---|
| 4 | 5 | 6 |
| 7 | 8 | 9 |
顺时针旋转后:
| 7 | 4 | 1 |
|---|---|---|
| 8 | 5 | 2 |
| 9 | 6 | 3 |
同理,逆时针也类似(这里由于篇幅原因,读者可以自行利用电脑上的notepad记事本模拟,这里就不写出来了)。
随后就是对于每一次的魔法操作做出对应的操作就可以了。
代码
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const int N = 505;
int n, m, a[N][N];
int help[N][N] = {0};
void init() {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
a[i][j] = (i - 1) * n + j;
}
}
}
void print(){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
void niShiZhen(int x, int y, int r) {
for(int i=x-r;i<=x+r;i++){
for(int j=y-r;j<=y+r;j++){
help[i][j]=a[i][j];
}
}
int xx=x-r,yy=y+r;
for(int i=x-r;i<=x+r;i++){
for(int j=y-r;j<=y+r;j++){
a[i][j]=help[xx][yy];
xx++;
}
xx=x-r;
yy--;
}
}
void shunShiZhen(int x, int y, int r) {
for(int i=x-r;i<=x+r;i++){
for(int j=y-r;j<=y+r;j++){
help[i][j]=a[i][j];
}
}
int xx=x+r,yy=y-r;
for(int i=x-r;i<=x+r;i++){
for(int j=y-r;j<=y+r;j++){
a[i][j]=help[xx][yy];
xx--;
}
xx=x+r;
yy++;
}
}
int main() {
cin >> n >> m;
init();
while(m--) {
int x, y, r, z;
cin >> x >> y >> r >> z;
if(z == 1) {
niShiZhen(x, y, r);
} else {
shunShiZhen(x, y, r);
}
}
print();
return 0;
}

浙公网安备 33010602011771号