BFS深搜+hashtable来判断是横线还是竖线
但是为啥还是90分啊呜呜!找不到原因
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int n, q, m;
int op;
const int maxn = 110;
char pic[maxn][maxn];
int hashtable[maxn][maxn];
int inq[maxn][maxn];
int X[4] = { 0,0,1,-1 };
int Y[4] = { 1,-1,0,0 };
struct node {int x;int y;
}Node;
int judge(int x, int y)
{if (x >&#61; m || x < 0 || y >&#61; n || y < 0) return 0;if (hashtable[y][x] !&#61; 0 || inq[y][x] &#61;&#61; 1) return 0;return 1;
}
void BFS(int x,int y,char c)
{queue<node> Q;Node.x &#61; x; Node.y &#61; y;Q.push(Node);inq[y][x] &#61; 1;pic[y][x] &#61; c;while (!Q.empty()){node top &#61; Q.front();Q.pop();for (int i &#61; 0; i < 4; i&#43;&#43;){int newX &#61; top.x &#43; X[i];int newY &#61; top.y &#43; Y[i];if (judge(newX, newY)){Node.x &#61; newX;Node.y &#61; newY;Q.push(Node);inq[newY][newX] &#61; 1;pic[newY][newX] &#61; c;}}}
}
int main() {scanf("%d %d %d",&m,&n,&q);getchar();for (int y &#61; 0; y < n; y&#43;&#43;){for (int x &#61; 0; x < m; x&#43;&#43;){pic[y][x] &#61; &#39;.&#39;;}}fill(hashtable[0],hashtable[0]&#43;maxn*maxn,0);for (int i &#61; 0; i < q; i&#43;&#43;){scanf("%d",&op);if (op&#61;&#61;1){fill(inq[0],inq[0]&#43;maxn*maxn,0);int x, y;char c[3];scanf("%d %d %s", &x, &y, c);BFS(x,y,c[0]);}else{int x1, y1, x2, y2;scanf("%d %d %d %d",&x1,&y1,&x2,&y2); if (x1 &#61;&#61; x2){if (y1 > y2)swap(y1,y2);for (int y &#61; y1; y <&#61; y2; y&#43;&#43;){if(hashtable[y][x1]&#61;&#61;0)hashtable[y][x1] &#61; 2;elsehashtable[y][x1] &#61; 3;}}else{if (x1 > x2)swap(x1,x2);for (int x &#61; x1; x <&#61; x2; x&#43;&#43;){if (hashtable[y1][x] &#61;&#61; 0)hashtable[y1][x] &#61; 1;elsehashtable[y1][x] &#61; 3;}}}}for (int y &#61; 0; y < n; y&#43;&#43;){for (int x &#61; 0; x < m; x&#43;&#43;){if (hashtable[y][x] &#61;&#61; 1)pic[y][x] &#61; &#39;-&#39;;else if (hashtable[y][x] &#61;&#61; 2)pic[y][x] &#61; &#39;|&#39;;else if (hashtable[y][x] &#61;&#61; 3)pic[y][x] &#61; &#39;&#43;&#39;;else;}}for (int y &#61; n-1; y>&#61;0;y--){for (int x &#61; 0; x < m; x&#43;&#43;){printf("%c", pic[y][x]);}printf("\n");}return 0;
}