【玲珑杯 1046】【记忆模拟】chess play【n*m棋盘,11xy表示(x,y)位置加白棋,12xy表示(x,y)位置加黑棋,2 x1 x2表示交换x1和x2这两行】

传送门:http://www.ifrog.cc/acm/problem/1046

思路:

显然不可以纯暴力地去怼,只需要一个数组去记录第i行目前真正的在cur[i],然后交换操作只需要改变记录数组的值,实现O(1)交换。复杂度O(q*n)

代码:

#include <iostream>
#include <stdio.h> 
#include <algorithm>
#include <string.h>
using  namespace  std;
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define rep(i,k,n) for(int i=k;i<=n;i++)

template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
const int N=1e3+10;

int cur[N], g[N][N];

int  main(){
  int T;
  read(T);
  while(T--){
    int n, m, q;
    mst(g, 0);
    read(n), read(m), read(q);
    rep(i, 1, n)cur[i] = i;
    while(q--){
      int op, col, x, y;
      read(op);
      if(op == 1){
        read(col), read(x), read(y);
        g[cur[x]][y] = col;
      }
      else{
        read(x), read(y);
        swap(cur[x], cur[y]);
      }
    }
    rep(i, 1, n){
      rep(j, 1, m){
        if(g[cur[i]][j] == 0)printf(".");
        else if(g[cur[i]][j] == 1)printf("w");
        else printf("b");      
      }
      printf("\n");
    }
  }
  return 0;
}

描述:

1046 - chess play

Time Limit:10s Memory Limit:64MByte

Submissions:775Solved:264

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.....


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值