LonLife 1046 chess play

来源:互联网 发布:php解析markdown 编辑:程序博客网 时间:2024/05/21 10:03
1046 - chess play

Time Limit:10s Memory Limit:64MByte

Submissions:717Solved:241

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;int n,m;char map[1100][1100];char temp[1100];int main(){int t,a,x,y,x1,y1,q,i,j,k,b;scanf("%d",&t);while(t--){scanf("%d%d%d",&n,&m,&q);for(i=0;i<n;i++){for(j=0;j<m;j++){map[i][j]='.';}}while(q--){scanf("%d",&b);if(b==1){scanf("%d%d%d",&a,&x,&y);if(a==1){map[x-1][y-1]='w';}else if(a==2){map[x-1][y-1]='b';    }}else{scanf("%d%d",&x1,&y1);                strcpy(temp,map[x1-1]);  strcpy(map[x1-1],map[y1-1]); strcpy(map[y1-1],temp);}}for(i=0;i<n;i++){printf("%s\n",map[i]);}}return 0;}


0 0