CCF_ 201512-3_画图
Posted 冷暖知不知
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CCF_ 201512-3_画图相关的知识,希望对你有一定的参考价值。
直接模拟就行了,注意坐标系方向与平常数组不一样,填充操作用深搜和广搜都可以,这里用了广搜。
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; struct point{ int x,y; }; int m,n,q,dir[][2] = {{0,1},{0,-1},{-1,0},{1,0}}; char a[105][105]; void line() { int x1,x2,y1,y2; cin >> x1 >> y1 >> x2 >> y2; if(x1 == x2) { int down = min(y1,y2),up = max(y1,y2); for(int i = down;i <= up;i++) { if(a[i][x1] == ‘-‘ || a[i][x1] == ‘+‘) a[i][x1] = ‘+‘; else a[i][x1] = ‘|‘; } } else { int left = min(x1,x2),right = max(x1,x2); for(int i = left;i <= right;i++) { if(a[y1][i] == ‘|‘ || a[y1][i] == ‘+‘) a[y1][i] = ‘+‘; else a[y1][i] = ‘-‘; } } } void bfs() { point start; char str; cin >> start.x >> start.y >> str; a[start.y][start.x] = str; queue<point> q; q.push(start); while(!q.empty()) { int x = q.front().x,y = q.front().y; q.pop(); for(int i = 0;i < 4;i++) { int xx = x+dir[i][0],yy = y+dir[i][1]; if(xx < 0 || xx >= m || yy < 0 || yy >= n || a[yy][xx] == ‘-‘ || a[yy][xx] == ‘|‘ || a[yy][xx] == ‘+‘ || a[yy][xx] == str) continue; point temp; temp.x = xx; temp.y = yy; q.push(temp); a[yy][xx] = str; } } } int main() { cin >> m >> n >>q; for(int i = 0;i < n;i++) { for(int j = 0;j < m;j++) a[i][j] = ‘.‘; } while(q--) { int flag; cin >> flag; if(flag) bfs(); else line(); } for(int i = n-1;i >= 0;i--) { for(int j = 0;j < m;j++) cout << a[i][j]; cout << endl; } return 0; }
以上是关于CCF_ 201512-3_画图的主要内容,如果未能解决你的问题,请参考以下文章