CSP 201512-3 画图

.......

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
char mp[N][N];
int n, m, q;
int dir[][2] = {0, 1, 0, -1, 1, 0, -1, 0};
void slv1() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 == x1 ? 0 : (x2 > x1 ? 1 : -1);
  int dy = y2 == y1 ? 0 : (y2 > y1 ? 1 : -1);
  char d;
  if (x1 == x2) d = '|';
  else d = '-';
  while (1) {
    if (mp[y1][x1] == '|' && d == '-') {
      mp[y1][x1] = '+';
    } else if (mp[y1][x1] == '-' && d == '|') {
      mp[y1][x1] = '+';
    } else {
      if (mp[y1][x1] != '+')
        mp[y1][x1] = d;
    }
    if (x1 == x2 && y1 == y2) break;
    x1 += dx;
    y1 += dy;
  }
}
void slv2() {
  int x, y;
  char c;
  cin >> x >> y >> c;
  vector<vector<bool>> vis(110, vector<bool>(110, false));
  queue<pair<int, int>> q;
  q.push({x, y});
  auto check = [&](int xx, int yy) {
    if (xx >= 0 && xx < m && yy >= 0 && yy < n && mp[yy][xx] != '-'
        && mp[yy][xx] != '+' && mp[yy][xx] != '|' && !vis[xx][yy]) {
      return true;
    }
    return false;
  };
  if (check(x, y)) {
    mp[y][x] = c;
    vis[x][y] = true;
  }
  while (!q.empty()) {
    auto cur = q.front();
    q.pop();
    int x1 = cur.first;
    int y1 = cur.second;
    for (int i = 0; i < 4; i++) {
      int xx = x1 + dir[i][0];
      int yy = y1 + dir[i][1];
      if (check(xx, yy)) {
        vis[xx][yy] = true;
        mp[yy][xx] = c;
        q.push({xx, yy});
      }
    }
  }

}
int main() {
  cin >> m >> n >> q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      mp[i][j] = '.';
    }
  }
  for (int i = 1; i <= q; i++) {
    int op;
    cin >> op;
    if (op == 0) {
      slv1();
    } else {
      slv2();
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      cout << mp[i][j];
    }
    cout << '\n';
  }
}

/*
4 2 3
1 0 0 B
0 1 0 2 0
1 0 0 A
 */

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值