洛谷P4924 [1007] 魔法少女小Scarlet 题解
1.洛谷P1028 [NOIP 2001 普及组] 数的计算 题解2.洛谷P1464 Function 题解3.洛谷P2440 木材加工 题解4.洛谷P2678 [NOIP 2015 提高组] 跳石头 题解5.洛谷P1314 [NOIP 2011 提高组] 聪明的质监员 题解6.洛谷P1083 [NOIP 2012 提高组] 借教室 题解7.洛谷P1902 刺杀大使 题解8.洛谷P1873 [COCI 2011/2012 #5] EKO / 砍树 题解9.洛谷P2280 [HNOI2003] 激光炸弹 题解10.洛谷P8218 【深进1.例1】求区间和 题解11.洛谷 P1719 最大加权矩形 题解12.洛谷 P2367 语文成绩 题解13.洛谷P1387 最大正方形 题解14.洛谷P1014[NOIP 1999 普及组] Cantor 表 题解15.洛谷P1563 [NOIP 2016 提高组] 玩具谜题 题解
16.洛谷P4924 [1007] 魔法少女小Scarlet 题解
17.洛谷P1518 [USACO2.4] 两只塔姆沃斯牛 The Tamworth Two 题解18.洛谷P1786 帮贡排序 题解19.洛谷P1990 覆盖墙壁 题解20.洛谷P1010 [NOIP 1998 普及组] 幂次方 题解21.洛谷P1259 黑白棋子的移动 题解22.洛谷P1281 书的复制 题解23.洛谷P1396 营救 题解24.洛谷PP1570 KC 喝咖啡25.洛谷P1661 扩散 题解26.洛谷P1843 奶牛晒衣服 题解洛谷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记录
本文作者:2789617221guo
本文链接:https://www.cnblogs.com/2789617221guo/p/18719753
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步