201512-3 画图 100分 62ms

点击前往试题目录:https://blog.csdn.net/best335/article/details/99550556
在这里插入图片描述

#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
typedef pair<int,int> P;
int main(){
	int m,n,q;
	char M[100][100],V[100][100],ch,F=char(1),T=char(0);
	memset(M,0,sizeof(M));
	cin>>m>>n>>q;
	for(int i=0,c,x1,y1,x2,y2;i<q;++i){
		cin>>c;
		if(c==0){
			cin>>x1>>y1>>x2>>y2;
			if(x1==x2){
				for(int y=min(y1,y2),ny=max(y1,y2)+1;y<ny;++y){
					if(M[y][x1]!='+') M[y][x1]=M[y][x1]=='-'?'+':'|';
				}
			}
			else{
				for(int x=min(x1,x2),nx=max(x1,x2)+1;x<nx;++x)
					if(M[y1][x]!='+') M[y1][x]=M[y1][x]=='|'?'+':'-';
			}
		}
		else{
			cin>>y1>>x1>>ch;
			queue<P> q;
			q.push(P(x1,y1));
			for(int x=0;x<n;++x)
				for(int y=0;y<m;++y)
					V[x][y]=M[x][y]=='-'||M[x][y]=='|'||M[x][y]=='+'?F:T;
			V[x1][y1]=F;
			while(!q.empty()){
				P p=q.front();q.pop();
				int &x=p.first,&y=p.second,lx=x-1,rx=x+1,ly=y-1,ry=y+1;
				M[x][y]=ch;
				if(lx>-1&&V[lx][y]==T) V[lx][y]=F,q.push(P(lx,y));
				if(rx<n&&V[rx][y]==T) V[rx][y]=F,q.push(P(rx,y));
				if(ly>-1&&V[x][ly]==T) V[x][ly]=F,q.push(P(x,ly));
				if(ry<m&&V[x][ry]==T) V[x][ry]=F,q.push(P(x,ry));
			}
		}
	}
	for(int i=n-1;i>-1;--i){
		for(int j=0;j<m;++j)
			cout<<(M[i][j]==T?'.':M[i][j]);
		cout<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值