玲珑oj 1046- chess play【水】
来源:互联网 发布:java语言程序设计答案 编辑:程序博客网 时间:2024/05/20 23:55
1046 - chess play
Time Limit:10s Memory Limit:64MByte
Submissions:745Solved:253
DESCRIPTION
Bob has a n×mn×m chessboard, which has two kinds of chess pieces.one is black, and the other is white.
As for chessboard, you can do three operations:
- 1 1 x y1 1 x y (means add a white chess piece to position (x, y))
- 1 2 x y1 2 x y(means add a black chess piece to position (x, y))
- 2 x1 x22 x1 x2(means swap the x1x1 row and x2x2 row)
(note: if you add one new chess to a position where there already is a chess, you need throw the old chess away firstly.)
In the initial time the chessboard is empty, and your mission is to show the final chessboard.
Please look at the example for more details.
INPUT
There are multiple test cases.The first line is a number T (T ≤10T ≤10), which means the number of cases.For each case, the first line contains three integers n, m and q(1≤n,m≤103,1≤q≤106)(1≤n,m≤103,1≤q≤106). Then follow qq lines are the operations.As for each operation, 1≤xi,yi≤n1≤xi,yi≤n
OUTPUT
Print n lines which containing m characters - the final chessboard.
SAMPLE INPUT
22 2 21 1 1 12 1 24 3 41 1 1 12 1 21 2 1 12 2 3
SAMPLE OUTPUT
..w.b.....w.....
SOLUTION
“玲珑杯”ACM比赛 Round #4
解题思路:
题目很简单就是三种不同的输入,对应是三种不同的操作,我们只需要将输出行号保存一下,当需要交换行时交换序列中的数就行了。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char map[2000][2000];int out[2000];void init(int n,int m){for(int i=0;i<=n;i++){for(int j=0;j<=m;j++){map[i][j]='.';}}for(int i=0;i<=n;i++){out[i]=i;}}void shift(int x,int y){int z;z=out[x];out[x]=out[y];out[y]=z;}int main(){int T;int n,m,q;scanf("%d",&T);while(T--){scanf("%d%d%d",&n,&m,&q);init(n,m);for(int i=0;i<q;i++){int yi,er,x1,y1;scanf("%d",&yi);if(yi==2){scanf("%d%d",&x1,&y1);shift(x1,y1);}else{scanf("%d",&er);if(er==1){scanf("%d%d",&x1,&y1);map[out[x1]][y1]='w';}else{scanf("%d%d",&x1,&y1);map[out[x1]][y1]='b';}}}for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){printf("%c",map[out[i]][j]);}printf("\n");}}return 0;}
0 0
- 玲珑oj 1046- chess play【水】
- 玲珑1046 chess play
- 【玲珑学院 1046 - chess play】
- 玲珑杯-【 chess play】
- 玲珑比赛 A -- chess play【记忆模拟】
- LonLife 1046 chess play
- 1046 - chess play
- “玲珑杯”ACM比赛 Round #4 A -- chess play
- “玲珑杯”ACM比赛 Round #4 A -- chess play 【记忆模拟】
- 【玲珑杯 1046】【记忆模拟】chess play【n*m棋盘,11xy表示(x,y)位置加白棋,12xy表示(x,y)位置加黑棋,2 x1 x2表示交换x1和x2这两行】
- SDUT oj 玲珑龟
- 玲珑oj 1074
- 玲珑oj 1072 - Capture
- 玲珑oj Digital Count
- 玲珑OJ 1047
- 玲珑oj 1096
- 玲珑oj 1099
- 玲珑OJ 1100
- 构建高并发高可用的电商平台架构实践
- 硬件设计の运算放大器の一
- POJ 3169 Layout 差分约束系统
- Reducers may not dispatch actions
- 基础练习 特殊回文数
- 玲珑oj 1046- chess play【水】
- Linux文件与目录管理
- 解决redhat linux乱码的问题
- Android状态栏着色工具类
- 累啊
- 基础练习 回文数
- 编码中的setCharacterEncoding 理解,中文乱码的问题
- 用testlink来管理测试用例
- UVALIVE 7505 dp