泥豪!我是2789617221guo!欢迎来到我|

2789617221guo

园龄:1个月粉丝:2关注:2

2025-02-17 13:12阅读: 3评论: 0推荐: 0

洛谷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;
}

AC记录

AC,274ms,2.35MB

本文作者:2789617221guo

本文链接:https://www.cnblogs.com/2789617221guo/p/18719753

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   2789617221guo  阅读(3)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起