玲珑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(1n,m103,1q106)(1≤n,m≤103,1≤q≤106). Then follow qq lines are the operations.As for each operation, 1xi,yin1≤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